AVPlayer在后台模式下不会转到下一首歌曲 [英] AVPlayer not going to the next song when it is in background mode
问题描述
我正在使用AVPlayer播放URL中的歌曲集.我也可以在后台模式下播放歌曲.但是问题出在背景模式下,下一首歌曲没有播放.它执行代码,但是[播放器播放];方法不起作用.但是,如果播放1首歌曲,尽管它进入了背景模式,但它会播放到最后.
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.
请帮助我 谢谢
推荐答案
好吧,您现在可能已经知道了,但是对于其他可能遇到此问题的人,请尝试将其放在viewDidLoad中:
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];
假设您有这个:
NSError *setCategoryErr = nil;
NSError *activationErr = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:&setCategoryErr];
[[AVAudioSession sharedInstance] setActive:YES error:&activationErr];
在AppDelegate.m中的didFinishLaunch下,并且您的info.plist设置为在后台播放音频.
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.
这篇关于AVPlayer在后台模式下不会转到下一首歌曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!