公司项目有这个需求,
脑洞大开,想到个比较取巧的方法,方法很简单,只需要一段代码
这个属性是用来枚举播放类型的
@property (nonatomic, readonly) MPMoviePlaybackState playbackState
typedef NS_ENUM(NSInteger, MPMoviePlaybackState) {
MPMoviePlaybackStateStopped, //停止播放
MPMoviePlaybackStatePlaying, //正在播放
MPMoviePlaybackStatePaused, //暂停
MPMoviePlaybackStateInterrupted, //中断
MPMoviePlaybackStateSeekingForward, //快进
MPMoviePlaybackStateSeekingBackward //快退
} MP_API_IOS_DEPRECATED_MACOS_TVOS_PROHIBITED(3.2, 9.0, 10.12.2, 10.12.2, 3.2, 9.0);
用来监听播放状态发生改变
MPMoviePlayerPlaybackStateDidChangeNotification
我们可以用这个属性来监听视频播放状态的变化,当视频被快进时,记录当前播放时间,快进结束恢复正在播放时,让视频从被记录的播放时间开始播放,变相实现视频的禁止快进
上代码
CGFloat videoPlayNowTime; //用来记录快进时的播放时间
BOOL _isSeekingForward; //用来判断是否从快进恢复到正在播放
注册通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getVideoPlayState) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];
通知调用方法
-(void)getVideoPlayState{
//视频被快进时
if (self.videoPlay.playbackState == MPMoviePlaybackStateSeekingForward) {
videoPlayNowTime = self.videoPlay.currentPlaybackTime;
_isSeekingForward = YES;
}
//视频恢复正在播放时
if (self.videoPlay.playbackState == MPMoviePlaybackStatePlaying){
if (_isSeekingForward) { //判断是否从快进状态恢复到正在播放状态
_isSeekingForward = NO;
[self.videoPlay setCurrentPlaybackTime:videoPlayNowTime];
[self.videoPlay play];
}
}
}
小白总结,欢迎打脸指正