后台切换回来会自动播放 设置代理shouldResumePlaybackWhenApplicationDidBecomeActiveFromBackgroundForURL为NO无效
我这边发现问题可能出现在"JPVideoPlayer.m" JPDebugLog(@"AVPlayerItemStatusReadyToPlay"); self.playerStatus = JPVideoPlayerStatusReadyToPlay; // When get ready to play note, we can go to play, and can add the video picture on show view. if (!self.playerModel) return; [self callPlayerStatusDidChangeDelegateMethod]; [self.playerModel.player play]; [self displayVideoPicturesOnShowLayer];
切换回来会触发这个方法:
- (void)playerItemDidPlayToEnd:(NSNotification *)notification {}
我发现源码里有声明这么个属性playerStatus_beforeEnterBackground 但是作者没有用到它; 我在源码基础上加了这些代码 暂时解决了这个问题
- (void)applicationStateMonitor:(JPApplicationStateMonitor *)monitor applicationStateDidChange:(JPApplicationState)applicationState{ ... else if(applicationState == JPApplicationStateDidEnterBackground){ self.videoPlayer.playerStatus_beforeEnterBackground = self.videoPlayer.playerStatus; ... } else if (applicationState == JPApplicationStateDidBecomeActive){ self.videoPlayer.playerStatus_beforeEnterBackground = JPVideoPlayerStatusUnknown; } }
然后
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context{ ... case AVPlayerItemStatusReadyToPlay:{ ... if(self.playerStatus_beforeEnterBackground == JPVideoPlayerStatusPause){ [self.playerModel.player pause]; } else{ [self.playerModel.player play]; } ... }
暂时不确定是否会引起其他什么bug 希望作者看到这条留言后能给个回复