2017-03-29 74 views
0

蘋果電視AVPlayerViewController允許用戶按下siri遙控器的最右端/最左端快進/快退。有沒有任何委託方法來跟蹤這一點。我確實遇到了以下方法,但它的唯一功能足以跟蹤拖拽或尋求前進10秒。有沒有其他方式跟蹤快速前進,缺少跟蹤avplayeritems currentTime屬性?跟蹤快進/快退電視

- (void)playerViewController:(AVPlayerViewController *)playerViewController 
willResumePlaybackAfterUserNavigatedFromTime:(CMTime)oldTime 
         toTime:(CMTime)targetTime 

回答

0

據我所知,沒有辦法從AVPlayerViewControllerDelegate取回信息。

但由於AVPlayerViewController在那時在內部使用AVPlayer的注入實例......您可以創建AVPlayer的自定義子類來跟蹤該使用情況。

class ViewController: AVPlayerViewController { 

    override func viewDidAppear(_ animated: Bool) { 
     super.viewDidAppear(animated) 
     play(stream: URL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")!) 
    } 

    // MARK: - Private 

    private func play(stream: URL) { 
     let asset = AVAsset(url: stream) 
     let playetItem = AVPlayerItem(asset: asset) 
     player = MyPlayer(playerItem: playetItem) 
     player?.play() 
    } 
} 


class MyPlayer: AVPlayer { 

    override func seek(to time: CMTime, toleranceBefore: CMTime, toleranceAfter: CMTime, completionHandler: @escaping (Bool) -> Void) { 
     super.seek(to: time, toleranceBefore: toleranceBefore, toleranceAfter: toleranceAfter, completionHandler: completionHandler) 

     print("The user did seek to: \(time)") 
    } 
} 
+0

這不適用於通過按住Siri Remote的左上或右上按鈕實現的快進和快退。 –