开发者

AVAudioSession background mode problem

I have set up my AVAudioSession to play music in the background

AVAudioSession *audioSession = [AVAudioSession sharedInstance];

NSError *setCategoryError = nil;
[audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];
if (setCategoryError) {
}

NSError *activationError = nil;
[audioSession setActive:YES error:&activationError];
if (activationError) { 
}

Also added 'Required background modes' in my plist file.

When I play a remote file and the iPhone enters the background the audio keeps playing as suspected. But when I play a song from the iPod开发者_如何学C inside my app (MPMediaItem URL) it won't continue to play in the background.

What am I missing?


You're not missing anything. When the user starts playing music from iPod, it will stop your app from playing any further audio.

If you mean something else, please leave a note and I'll update this answer.

Edit: You should start iPod music by setting the queue on the relevant instance of MPMusicPlayerController, and then sending it the -play message. If you use the URL provided by the MPMediaItem object with an AVAudioPlayer instance or similar, it will be routed differently and may not be able to continue playing in the background.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜