2011-01-06 62 views
0

所以我討厭不得不問這個問題,但我花了一段時間搜索Apple的文檔和Google沒有用。我只是試圖爲我的應用程序設置AVAudioSession類別,當applicationDidFinishLaunching時。我有一個播放音頻流的應用程序,我希望它在應用程序進入後臺時繼續播放,所以我試圖使用播放類別。這裏是我的AppDelegate.m代碼:在AppDelegate.m中設置AVAudioSession類別

- (void)applicationDidFinishLaunching:(UIApplication *)application 
{ 
// Set AudioSession 
NSError *sessionError = nil; 
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&sessionError]; 
[[AVAudioSession sharedInstance] setActive:YES error:&sessionError]; 
[[AVAudioSession sharedInstance] setDelegate:self]; 

// create window and set up navigation controller 
[window addSubview:myNavController.view]; 
[window makeKeyAndVisible]; 

} 

# pragma mark - 
# pragma mark AVAudioSession Delegate Methods 
- (void)beginInterruption { 
} 
- (void)endInterruption { 
} 
- (void)endInterruptionWithFlags:(NSUInteger)flags { 
} 
- (void)inputIsAvailableChanged:(BOOL)isInputAvailable { 
} 

有了這個代碼,音頻淡出任何時候我打的home鍵,把 在後臺的應用程序。任何幫助非常感謝,我希望它 是一個快速修復類型的答案任何人誰已經做到了這一點。

回答

2

如果您尚未完成,請首先將UIBackgroundModes鍵添加到您的Info.plist文件中。 更多信息here

如果你已經做到了,你使用哪個框架來播放媒體?

1

感謝您的幫助艾琳。除了我只想提供它爲我工作所必需的步驟之外,你的答案几乎是正確的。我讀了您發佈的蘋果文檔和出於某種原因離開了這些重要的細節了:

  1. 當您在的.plist文件中添加UIBackgroundModes關鍵,你必須做出一個數組。
  2. 數組的項目0的值應該是音頻。

當然,您的應用程序還應該設置其音頻會話類別並設置此鍵的組合。

相關問題