我是为了实现这个AVPlayerController。尚未在设备中进行测试。
首先在 AVPlayercontroller 中实现播放/暂停手势:
UITapGestureRecognizer *tapGestureRec = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(PlayPause)];
tapGestureRec.allowedPressTypes = @[@(UIPressTypePlayPause)];
[self.playerViewController.view addGestureRecognizer: tapGestureRec];
实现手势方法并始终从中调用 play 方法:
-(void)PlayPause {
[self.playerViewController.player play];
NSLog(@"Do Anything or Nothing");
}
还添加观察者以捕获首次按下暂停按钮:
[player addObserver: self forKeyPath: @"rate" options: (NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context: nil];
然后从“rate”观察者的暂停事件中调用播放器播放方法:
// When rate is 0.0, it means the player has stopped
if (![self.player rate]) {
if(self.isLiveStream) {
[self.playerViewController.player play]; // Disable pause in Live stream
}
}
在viewDidLoad
中,将线性播放标志设置为 true 以禁用搜索控件:
self.playerViewController.requiresLinearPlayback = true;