我正在开发一个使用 AVPlayer
来流式传输实时媒体的 iOS 应用程序。当通过 Airplay 连接到 Apple TV 时,可以使用 Apple TV Remote 暂停和恢复内容。
我正在寻找禁用此功能的方法。
我曾尝试使用:- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent
,它适用于耳机遥控和锁屏控制事件,但不适用于 Apple TV。
我也尝试过使用 MPRemoteCommandCenter
,它也不会拦截来自 Apple TV 的事件。
最佳答案
我是来实现这个AVPlayerController的。尚未在设备中进行测试。
首先在 AVPlayercontroller 中实现播放/暂停手势:
UITapGestureRecognizer *tapGestureRec = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(PlayPause)];
tapGestureRec.allowedPressTypes = @[@(UIPressTypePlayPause)];
[self.playerViewController.view addGestureRecognizer: tapGestureRec];
实现手势方法并始终从中调用播放方法:
-(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;
关于ios - 如何禁用通过 Airplay 暂停/播放连接到 Apple TV 的 AVPlayer 的功能,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28006573/