AVPlayer not going to the next song when it is in background mode

蹲街弑〆低调 提交于 2020-01-15 11:22:42

问题


I am useing AVPlayer to play setof songs from urls. I can play songs in background mode too. But the problem is in background mode the next song is not playing. It excecute the code and but [player play]; method is not working. But If play 1 song it plays to the end though it goes to the background mode.

Please help me Thanks


回答1:


You should use AVQueuePlayer instead. This is working fine for me.




回答2:


Well, you probably have this figured out by now, but for anyone else who might come across this, try putting this in your viewDidLoad:

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

Assuming you have this :

NSError *setCategoryErr = nil;
NSError *activationErr  = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:&setCategoryErr];
[[AVAudioSession sharedInstance] setActive:YES error:&activationErr];

in your AppDelegate.m, under didFinishLaunch and your info.plist set up to play audio in the background.

Had the same problem, and this solved it for me.



来源:https://stackoverflow.com/questions/20965422/avplayer-not-going-to-the-next-song-when-it-is-in-background-mode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!