ios - 加载 youtube 视频后获取视频时长
问题描述
我正在做一个项目,我将 youtube 视频列表加载到 UITableView。至于加载和播放它们,我使用 YouTube-Player-iOS-Helper pod。根据我的理解,我使用“playerViewDidBecomeReady”委托方法来确定视频是否已加载,一旦调用,我将使用视频持续时间更新我的标签。但是由于某种原因,它不会一直更新。我的代码如下。我错过了什么
func playerViewDidBecomeReady(_ playerView: YTPlayerView) {
print("player is ready to play")
self.updateLabel(cell:cell,videoView:YTPlayer)
}
static func updateLabel(cell:UITableViewCell,videoView:YTPlayerView) {
var videoView = cell.viewWithTag(TABLE_CELL_TAGS.webView) as! YTPlayerView!
let durationSecs = String(describing: videoView?.duration())
var time = videoView?.duration()
cell.textLabel.text = time
}
我的 UITableViewDelegates 如下
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier:Utils.isIpad() ? "iPadVideosCell":"videosCell", for: indexPath)
self.cell = cell
var videoView = cell.viewWithTag(5) as! YTPlayerView!
self.YTPlayer = videoView
videoView?.delegate = self
return cell
}
解决方案
推荐阅读
- javascript - Firestore 仅监听根组件
- html - CSS Flexbox 2 列,但一列响应式
- python - 图论:python中树中的路径
- java - 原始功能接口 lambda 调用上的 ClassCastException
- flutter - 通过firebase推送通知进行路由时获取空参数颤动
- javascript - 为函数交换常量
- javascript - 如何从 .fields 中获取元素
- sql - 基于连续数据的行编号?
- typescript - 使用 Observable 数组自动完成 Angular 材料芯片
- html - 为什么 div 元素表现得像一个容器?