7

I have an application that plays video using AVPlayer and AVPlayerLayer. In my app, I'm able to play audio when the app is locked by setting the player property of my AVPlayerLayer to nil when the application enters the background:

-(void)appEnteredBackgroundNotification:(NSNotification *)notification {

    [[self playerLayer] setPlayer:nil];

}

However, when I do this, the audio will lag/blip for around 0.5 seconds. This sounds really really bad for the end user. Same goes for when the app enters foreground and I re-set the player property.

How can I avoid this audio blip? As a test I've tried removing the player in a background thread to no avail.

Update: I spoke with an Apple engineer at WWDC and they said that this issue is a bug on their end (so far not fixed in iOS 9) and this approach is the correct approach. Great...

Aaron Wojnowski
  • 6,352
  • 5
  • 29
  • 46

1 Answers1

-1

I think may not you call pause before setting to nil and vice versa. And, try calling prepare before play.

khunshan
  • 2,662
  • 4
  • 28
  • 34
  • Thanks for the reply. My goal is to have the music go into the background without stopping so I paused the audio, removed the player layer's player, and then unpaused it. Unfortunately it looks like the same blip is existent. – Aaron Wojnowski May 25 '15 at 14:43
  • Thats really easy, you need to create an AVSession and implement Media Center methods. (Y) – khunshan May 26 '15 at 09:28