在播放视频黑屏时使用avplayerkit问题

时间:2018-12-05 10:51:40

标签: ios swift avplayerviewcontroller avkit

您好,我是Swift的新手,我正在使用AVPlayerViewController来从我的网址中获取原始视频,但问题是我无法加载仅黑屏显示让我显示代码的视频

代码

import UIKit
import AVKit
import AVFoundation

class ViewController: UIViewController {

    @IBOutlet weak var viewPlayer: UIView!
    var player: AVPlayer!
    var avpController = AVPlayerViewController()
    var url = "https://www.youtube.com/watch?v=HsQvAnCGxzY"
    override func viewDidLoad() {
        super.viewDidLoad()
        let url = URL(string: self.url)

        player = AVPlayer(url: url!)

        avpController.player = player

        avpController.view.frame.size.height = viewPlayer.frame.size.height

        avpController.view.frame.size.width = viewPlayer.frame.size.width

        self.viewPlayer.addSubview(avpController.view)
        // Do any additional setup after loading the view, typically from a nib.
    }

}

请参考给出的代码,并告诉我我做错了什么地方,以便我可以播放视频

0 个答案:

没有答案