0

I have implemented player AVPlayerViewController on tvOS using AVQueuePlayer. The playback of videos works as expected but on all videos following the first the scrubber / time slider shows thumbnails for the first video.

The player is being setup using the following code:

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)

                }

            }
        }

    }
}

I have also instantiated the AVQueuePlayer using the code below as I thought there might be an issue with the initial queue setup but the issue remain: AVQueuePlayer(playerItem: mainVideo)

Edward Ford
  • 1,631
  • 3
  • 13
  • 25

0 Answers0