[问题]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