AVPlayer not going to the next song when it is in

2019-07-29 04:37发布

问题:

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.



标签: ios7 avplayer