AVQueuePlayer scrubber缩略图始终是第一个视频

时间:2016-02-17 21:02:32

标签: swift video slider avplayer avqueueplayer

我已经使用AVQueuePlayer在tvOS上实现了播放器AVPlayerViewController。视频播放按预期工作,但在第一个播放器/时间滑块显示第一个视频的缩略图之后的所有视频上。

正在使用以下代码设置播放器:

class TFLPlayerController: AVPlayerViewController, AVPlayerViewControllerDelegate {

var queuePlayer = AVQueuePlayer()
...

func addVideoToQueue(video: Video, after: AVPlayerItem?){

  let mainVideo = AVPlayerItem(URL: NSURL(string: videoURL)!)

  self.queuePlayer.insertItem(mainVideo, afterItem: nil)

}

func readyToPlay() {

    self.addVideoToQueue(videoRecord, after: nil)

    self.player = self.queuePlayer

    if let currentItem = queuePlayer.currentItem {
        // Set time to get make a call to the API for the next video
        let callUpNextAPITime = CMTimeMakeWithSeconds(0.5, currentItem.asset.duration.timescale)
        let callUpNextAPITimeValue = NSValue(CMTime: callUpNextAPITime)

        let getUpNextObserver = queuePlayer.addBoundaryTimeObserverForTimes([callUpNextAPITimeValue], queue: dispatch_get_main_queue(), usingBlock: { () -> Void in

            self.getUpNext()

        })


    }

    self.player?.play()

}


func getUpNext(){

    // Get the next video to play
    let playlistId = presentingPlaylist?.identifier ?? nil

    if let currentItem = self.queuePlayer.currentItem {

        // Get the current items id
        let currentVideoId = itemVideo[currentItem]?.identifier

        if let currentVideoId = currentVideoId {
            // Call API to get the next video to be played from the server
            dataLayer.getNextVideo(currentVideoId, playlistIdentifier: playlistId) {
                video, error in

                ...

                if let nextVideo = video {

                    let currentVideo: AVPlayerItem = self.queuePlayer.currentItem!

                    self.addVideoToQueue(nextVideo, after: currentVideo)

                }

            }
        }

    }
}

我还使用下面的代码实例化了AVQueuePlayer,因为我认为初始队列设置可能存在问题,但问题仍然存在:     AVQueuePlayer(playerItem:mainVideo)

0 个答案:

没有答案