无法使用AVPlayerController重现视频流

时间:2017-05-13 17:43:28

标签: ios swift3 avplayer avplayerviewcontroller

我有一个TableViewController,当我点击任何单元格时,我调用 prepareforsegue 函数来加载 AVPlayerViewController ,它应该重现通过相同函数传递的流。当我单击选项卡时,该功能被调用为右,显示视频播放器,但它不会初始化 urlCana​​le 变量。

class HomeController: UITableViewController {
...
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        let nuovoCanale = URL(string: menuItems[indexPath.row].stream_url!)
        self.performSegue(withIdentifier: "riproduciCanale", sender: nuovoCanale)

    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "riproduciCanale"{
            if let nextViewController = segue.destination as? VideoPlayerController{
                nextViewController.urlCanale = sender as? URL //Or pass any values
                print("cambio canale")                
            }
        }

这是AVPlayerViewController代码,每次变量urlCana​​le都为null:

class VideoPlayerController: AVPlayerViewController {
    var urlCanale : URL!

override func viewDidLoad() {
    //super.viewDidLoad()
    if(urlCanale == nil){
        print("is nuuulllll")
        urlCanale = URL(string: "https://www.google.it")        
    }
    let playerItem = AVPlayerItem(url: urlCanale)
    player?.replaceCurrentItem(with: playerItem)
    player?.play()     
}

0 个答案:

没有答案