问题
I have a video player in an IOS App and I want to update the video when I click on a button, but I do not see how to manage this. (Note : it's not a list of video within a queue)
Here is the code for adding the AVPlayer:
let url = NSURL.fileURLWithPath(path)
let player = AVPlayer(URL: url)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
..
..
self.ViewForVideo.addSubview(playerViewController.view)
self.addChildViewController(playerViewController)
player.play()
回答1:
I have done like this : each time I want to change the video I create a new AVPlayer
and affect it to the playerViewController.player
like this
let url = NSURL.fileURLWithPath(path)
let player = AVPlayer(URL: url)
playerViewController.player = player
来源:https://stackoverflow.com/questions/37763430/swift-how-to-update-url-of-video-in-avplayer-when-clicking-on-a-button