如何在iOS AVPlayerViewController上禁用搜索?
在tvOS上,如果我想允许播放/暂停但禁用搜索,我可以设置如何在iOS AVPlayerViewController上禁用搜索?,ios,avplayerviewcontroller,Ios,Avplayerviewcontroller,在tvOS上,如果我想允许播放/暂停但禁用搜索,我可以设置avPlayerViewController.requiresLinearPlayback=YES。但是,此属性在iOS中不存在。我如何在iOS上实现同样的功能?我不想使用avplayervewcontroller.showsPlaybackControls=NO,因为这样会阻止播放/暂停。我只想禁用搜索功能。此外,我不完全确定avplayervewcontroller.showsPlaybackControls=NO是否会完全阻止搜索,
avPlayerViewController.requiresLinearPlayback=YES
。但是,此属性在iOS中不存在。我如何在iOS上实现同样的功能?我不想使用avplayervewcontroller.showsPlaybackControls=NO
,因为这样会阻止播放/暂停。我只想禁用搜索功能。此外,我不完全确定avplayervewcontroller.showsPlaybackControls=NO
是否会完全阻止搜索,因为有人可以插入带有控制按钮的耳机并按下物理“向前跳”按钮,我通过扩展AVPlayer解决了这个问题。尽管苹果的文档说你应该而不是扩展AVPlayer,而且这样做有未定义的行为,但在测试中,在iOS 9到iOS 13上一切正常
@interface CustomAVPlayer : AVPlayer
@property BOOL seekingEnabled;
@end
@implementation CustomAVPlayer
- (instancetype)initWithPlayerItem:(AVPlayerItem *)item
{
self = [super initWithPlayerItem:item];
if (self) {
_seekingEnabled = YES;
}
return self;
}
- (void)seekToTime:(CMTime)time toleranceBefore:(CMTime)toleranceBefore toleranceAfter:(CMTime)toleranceAfter completionHandler:(void (^)(BOOL))completionHandler
{
// This prevents seeking at the lowest level, regardless of whatever shenanigans the view may be doing
if (_seekingEnabled)
[super seekToTime:time toleranceBefore:toleranceBefore toleranceAfter:toleranceAfter completionHandler:completionHandler];
else
[super seekToTime:self.currentTime toleranceBefore:toleranceBefore toleranceAfter:toleranceAfter completionHandler:completionHandler];
}
@end
现在我可以启用/禁用搜索,只需:player.seekingEnabled=(YES/NO)代码>