I am delving this part more than one day. Please suggest any idea.
I have to accomplish to play video.I have a list of videos. If the user makes it full-screen video, th
I'd recommend Using the AVQueuePlayer. The queue player will automatically play the next item in the queue after the current item finishes playing. One think to keep in mind is that after an AVPlayerItem finishes playing, it will get removed from the queue, so if you are to go backwards you will have to either reset the queue or manually add new items to the queue here is an implementation of this.
In Swift reseting the queue should look something like this
func resetVideoQueue(video: string){
if let videos = Videos {
var queue: [AVPlayerItem] = []
switch video {
case "vid1":
queue.append(AVPlayerItem(URL: NSURL(string: videos["vid1"])!))
queue.append(AVPlayerItem(URL: NSURL(string: videos["vid2"])!))
queue.append(AVPlayerItem(URL: NSURL(string: videos["vid3"])!))
queue.append(AVPlayerItem(URL: NSURL(string: videos["vid4"])!))
break
case "vid2":
queue.append(AVPlayerItem(URL: NSURL(string: videos["vid2"])!))
queue.append(AVPlayerItem(URL: NSURL(string: videos["vid3"])!))
queue.append(AVPlayerItem(URL: NSURL(string: videos["vid4"])!))
break
case "vid3":
queue.append(AVPlayerItem(URL: NSURL(string: videos["vid3"])!))
queue.append(AVPlayerItem(URL: NSURL(string: videos["vid4"])!))
break
case "vid4":
queue.append(AVPlayerItem(URL: NSURL(string: videos["vid4"])!))
break
}
setVideoPlayer(queue)
}
}
internal func setVideoPlayer(queue: [AVPlayerItem]) {
queuePlayer = AVQueuePlayer(items: queue)
videoPlayerViewController.player = queuePlayer
presentViewController(videoPlayerViewController, animated: true) {
self.videoPlayerViewController.player?.play()
}
}
To move to the next item use the advanceToNextItem() method as suggested by MrHaze.
I did create a demo project where it is shown how to put a custom buttons on top of AVPlayer and they responds to clicks.
What was done: