my project
我连续几张桌子上有几个视频.
问题是它们是同步播放的.
在屏幕上1video和2video同步播放
如何在表格视图和cell.player上跟踪焦点单元格?.play().和其他细胞cell.player?.pause()
我的代码:
class MyViewController
//don't work
func tableView(_ tableView: UITableView,didEnddisplaying cell: UITableViewCell,forRowAt indexPath: IndexPath) {
if let cell = tableView.cellForRow(at: indexPath) as? ListViewCell {
cell.player?.pause()
}
}
//don't call
func tableView(_ tableView: UITableView,didUpdateFocusIn context: UITableViewFocusUpdateContext,with coordinator: UIFocusAnimationCoordinator) {
print("table view cell didUpdateFocusIn")
}
class MyTableviewCell
override func prepareForReuse() {
super.prepareForReuse()
player?.pause()
}
解决方法
我正在对您的项目进行一些更改.检查一下
https://yadi.sk/d/bQ-eIyMz3VF28V
https://yadi.sk/d/bQ-eIyMz3VF28V
决定滚动时要播放或暂停的视频:
func handleScroll() {
if let indexPathsForVisibleRows = myTableView.indexPathsForVisibleRows,indexPathsForVisibleRows.count > 0 {
var focusCell: ListViewCell?
for indexPath in indexPathsForVisibleRows {
if let cell = myTableView.cellForRow(at: indexPath) as? ListViewCell {
if focusCell == nil {
let rect = myTableView.rectForRow(at: indexPath)
if myTableView.bounds.contains(rect) {
cell.player?.play()
focusCell = cell
} else {
cell.player?.pause()
}
} else {
cell.player?.pause()
}
}
}
}
}
希望这会帮助你.