2011-03-02 86 views
10

我在背景模式下播放AVPlayer時遇到了問題,就像很多人在網絡上的任何地方一樣。我已經完成了我認爲應該工作的內容,但仍然沒有......我認爲我的問題可能是我設置和使用AudiSession和AVPlayer的地方。另一個AVPlayer在後臺播放流式音頻問題

1) 「音頻」 鍵是在我的Info.plist的UIBackgroundModes

2)AudioSession在AppDelegate中設置像這樣(在didFinishLaunchingWithOptions初始化):

AVAudioSession *audio = [[AVAudioSession alloc]init]; 
[audio setCategory:AVAudioSessionCategoryPlayback error:nil]; 
[audio setActive:YES error:nil]; 

3)I使用AVPlayer (而不是AVAudioPlayer)也在AppDelegate中實現。 (初始化在didFinishLaunchingWithOptions中,AudioSession後),AudioSession之後

// Load the array with the sample file 
NSString *urlAddress = @"http://mystreamadress.mp3"; 

//Create a URL object. 
self.urlStream = [NSURL URLWithString:urlAddress]; 
self.player = [AVPlayer playerWithURL:urlStream]; 
//Starts playback 
[player play]; 

而且還在,音頻每次暫停該應用程序進入後臺(當我按下「主頁」按鈕)...誰能幫助我請這個好嗎?

回答

5

順便說一下,問題只是模擬器。在iOS設備上正常工作