AVPlayerViewController保留PlaybackControls並加上自訂touch event

AVPlayerViewController的showsPlaybackControls屬性預設為YES
但如果自訂Gesture如下,會因為預設的單擊本來就賦予給隱藏/顯示PlaybackControls而無效
AVPlayerViewController *playerVC = [[AVPlayerViewController alloc]init];
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ChangeStatus)];
[tapGestureRecognizer setNumberOfTapsRequired:1];
[playerVC.view addGestureRecognizer:tapGestureRecognizer];

如果想要達到單擊影片,能依照當下播放與否決定是否加上PLAY的遮罩圖示(如下圖)
則可以改寫touchesBegan event如下
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    if (self.playerVC.player.rate == 1.0) {
        // 播放中
    } else if (self.playerVC.player.rate == 0.0) {
        // 已暫停
    }
}


沒有留言: