移动到背景时,AVPlayerLayer会让音乐停止播放一秒钟

时间:2017-07-05 14:31:47

标签: ios objective-c avplayer avplayerlayer

我删除/恢复AVPlayerLayer及其关联的AVPlayer,就像文档中的apple建议一样。

/* 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
}

音乐继续播放,但切换到背景/前景时会有一点停顿和播放。

问题是如何避免它?

0 个答案:

没有答案