AVPlayerLayer makes music pause for a second when fading to the background

I am removing / restoring AVPlayerLayer and associated AVPlayer like apple in docs.

/* Remove the AVPlayerLayer from its associated AVPlayer
    once the app is in the background. */
- (void)applicationDidEnterBackground:(UIApplication *)application {
  MyPlayerLayerView *playerView = <#Get your player view#>;
  [[playerView playerLayer] setPlayer:nil]; // remove the player
}

/* Restore the AVPlayer when the app is active again. */
- (void)applicationDidBecomeActive:(UIApplication *)application {
  MyPlayerLayerView *playerView = <#Get your player view#>;
  [[playerView playerLayer] setPlayer:_player]; // restore the player
}

      

And the music continues to play as it should, but there is a slight pause and play when switching to background / foreground.

The question is how to avoid it?

+3


source to share





All Articles