[問題]App音樂背景播放

作者: Cartel117 (無)   2014-04-16 17:13:49
NSError *activationErr = nil;
NSError *setCategoryErr = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryErr];
[[AVAudioSession sharedInstance] setActive: YES error: &activationErr];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
self.moviePlayer.contentURL = videoURL;
[self.moviePlayer play];
上面的程式碼是放在viewDidLoad裏面
該viewController是繼承MPMoviePlayerViewController
所以self.moviePlayer是MPMoviePlayerController class
測試機器是iphone 5(ios 7.1)
雖然可以背景播放音樂
可是當按下home鍵進入背景模式後
音樂就立刻停止播放
必須在主畫面把下面的選單拉起來
再按下播放按鈕才會播放
想問的是為何我按下home鍵後
音樂為什麼會停止播放
不繼續播放
有人知道該如何讓app進入背景還會繼續播放音樂
作者: hakushadow   2014-04-16 21:40:00
AudioSession那邊要記得設,另外Info.plist那邊background_mode要包含音樂的選項
作者: Cartel117 (無)   2014-04-17 09:41:00
我有在Info.plist裡的Required background modesApp plays audio or streams audio/video using AirPlay但是AudioSession要設什麼 可以告訴我該如何設定嗎 謝謝

Links booklink

Contact Us: admin [ a t ] ucptt.com