无法使用AVplayer显示视频阵列

时间:2019-06-14 07:11:58

标签: ios json avplayer

我有视频网址,我必须在表格视图中显示该网址。当我单击任何一个单元格时,它将转到详细信息视图,在该视图中将使用AVPayer播放视频。视频结束播放后,将播放下一个视频。当我运行代码时,视频正在一个接一个地播放。我只将声音和视频作为静止图像。当nex视频正在播放时,仅图像会更改为另一图像。屏幕上没有视频。

如何在屏幕上显示所有正在播放的视频?

class DetailView: UIViewController {

@IBOutlet weak var videoView: UIView!

var playerLayer: AVPlayerLayer!
var videoObject = [VideoData]()
private let vplayer = AVQueuePlayer()

override func viewDidLoad() {
    super.viewDidLoad()


    videoPlayerView.player = vplayer
    addAllVideosToPlayer()
}


private func addAllVideosToPlayer() {
    for video in videoObject {

        guard let urlString = try? URL(string: video.url) else{return}
        print(video.url)
        let asset = AVURLAsset(url: urlString)
        let item = AVPlayerItem(asset: asset)
        vplayer.insert(item, after: vplayer.items().last)
        playerLayer = AVPlayerLayer(player: vplayer)
        videoView.layer.addSublayer(playerLayer)

    }
}
override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    playerLayer.frame = videoView.bounds
}

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    vplayer.play()

}
}

0 个答案:

没有答案