How can I avoid the AVPlayerLayer `setPlayer` audio blip?
Asked Answered
B

1

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...

Brasilein answered 25/5, 2015 at 5:41 Comment(3)
same issue in iOS 9.2. actually in 9.2, it seems to have gotten worse for me on my iPhone 6s as compared to IOS 9.0. do you have any solution yet?Quadrivalent
@PranoyC No solution yet, unfortunately.Brasilein
it's also somehow depends on device hardware I think.Belindabelisarius
R
-1

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

Rogation answered 25/5, 2015 at 5:46 Comment(2)
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.Brasilein
Thats really easy, you need to create an AVSession and implement Media Center methods. (Y)Rogation

© 2022 - 2024 — McMap. All rights reserved.