我曾经使用 avplayer 在 UITableViewCell
上加载视频。我可以在 UITableViewCell
上加载视频,但无法暂停/播放视频。我不能做任何基本的功能,比如增加/减少音量。请任何人帮我解决这个问题。
这是我的代码:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell: FeedCell = tableView.dequeueReusableCell(withIdentifier: "VedioCell", for: indexPath) as! FeedCell
let videoURL = NSURL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
player = AVPlayer(url: videoURL! as URL)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = CGRect(x:0, y: 0, width: UIScreen.main.bounds.width, height: 200)
cell.PlayerView?.layer.addSublayer(playerLayer)
player.play()
return cell
}
我在这里使用了avplayer,但我无法访问
提前致谢。
试试这个
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: FeedCell = tableView.dequeueReusableCell(withIdentifier: "VedioCell", for: indexPath) as! FeedCell
let player = playerArray[indexPath.row]
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = CGRect(x:0, y: 0, width: UIScreen.main.bounds.width, height: 200)
cell.PlayerView?.layer.addSublayer(playerLayer)
cell.play.tag = indexPath.row
cell.play.addTarget(self, action: #selector(GetUpdatesButtonTouched), for: .touchUpInside)
return cell
}
@IBAction func GetUpdatesButtonTouched(_ sender: AnyObject) {
if sender.currentTitle == "lay" {
for i in 0..<10{
currentPlayer=playerArray[i]
currentPlayer.pause()
print("tag: \(sender.tag)")
print("tag: \(playerArray)")
currentPlayer=playerArray[sender.tag]
print("tag: \(currentPlayer)")
// handleVideoChageSlider(("" as AnyObject) as! UISlider)
currentPlayer.play()
sender.setTitle("ause", for: UIControlState.normal)
// let indexPath = tableView.indexPathForSelectedRow!
let cell: FeedCell = tableView.cellForRow(at:sender.indexPath)as! FeedCell
//print(currentCell.videoLabel.text)
//cell.slider.tag=indexPath.row
cell.slider.addTarget(self, action: #selector(handleVideoChageSlider), for:.valueChanged )
}
}
else if sender.currentTitle == "ause"{
for i in 0..<10{
currentPlayer=playerArray[i]
currentPlayer.pause()
sender.setTitle("lay", for: UIControlState.normal)
}
}
}
关于ios - 我无法在 tablecell 上暂停播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41034365/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |