gpt4 book ai didi

ios - 在表格单元格上播放视频

转载 作者:行者123 更新时间:2023-11-30 12:56:06 26 4
gpt4 key购买 nike

我使用自定义cell在单元格中播放视频。但它所做的只是向我显示空的 tableView cell,有人可以帮助我吗?

override func viewDidLoad() {
super.viewDidLoad()

let Custome = CustomeNavigation(nibName: "CustomeNavigation", bundle: nil)

self.view.addSubview(Custome.view)
Custome.lbl_customeTitle.text = "FEED"

tableView.frame = CGRect(x:0, y:0, width:view.bounds.width, height:view.bounds.height);
tableView.delegate = self
tableView.dataSource = self

tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")

self.view.addSubview(tableView)

}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "VedioCell", for: indexPath) as! FeedCell

let videoURL = NSURL(string: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
let player = AVPlayer(url: videoURL! as URL)

let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = cell.bounds

cell.layer.addSublayer(playerLayer)
player.play()

return cell
}

最佳答案

确保导入导入 AVKit导入 AVFoundation

你可以在cellForRowAtIndexPath中尝试这样的操作:

let cell: FeedCell = tableView.dequeueReusableCellWithIdentifier("VedioCell", forIndexPath: indexPath) as! FeedCell

let videoURL = NSURL(string: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
let player = AVPlayer(URL: videoURL!)

let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = cell.bounds

cell.layer.addSublayer(playerLayer)
cell?.playerView?.layer.addSublayer(playerLayer)
player.play()

return cell

如果您使用 swift3,则语法如下:

let videoURL = NSURL(string: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
let player = AVPlayer(url: videoURL! as URL)

let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = (cell?.bounds)!

cell?.layer.addSublayer(playerLayer)
cell?.playerView?.layer.addSublayer(playerLayer)
player.play()

如果您要显示其中许多内容,您还必须确保处理 cellForRowAtIndexPath

关于ios - 在表格单元格上播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40377822/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com