Creating a new AVPlayer in the background not working?

I play music with AVPlayer

. Now the fire goes off at a certain time NSTimer

, and I would like to move to another track. So I start to fade out of my AVPlayer and create a new AVPlayer instance to play the next song.

When in the foreground it works as expected. But when my application is in the background. The track playback disappears, but a new instance AVPlayer

does not start. Unable to create a new instance of AVPlayer in the background? or how can I make it play? Or is there another way to overlap the two tracks?

I could do the playback with AVQeueuPalyer

, but then I can't let the tracks overlap. Any suggestions?

- EDIT -

If it wasn't clear, I can play the background sound as much as I want. Just creating a new instance of AVPlayer in the background doesn't work.

+3


source to share


2 answers


The correct way to do what I wanted seems to be AVMutableComposition. That being said, I don't need multiple AVPlayers and a few other benefits. For more details: I summarized it in a blog post: http://www.postblog.me/2012/03/playing-multiple-overlapping-audio-tracks-in-background/



+2


source


Try adding a key called "UIBackgroundModes" (array) to your Info.plist application and adding the value "audio" to it. Then call

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:NULL];

      



And then you should be able to play audio in the background (you should reference the AVFoundation structure).

0


source







All Articles