YTPlayerView inside UITableViewCell(UITableViewCell 内的 YTPlayerView)
问题描述
我的 UITableViewCell 子类中有一个 YTPlayerView.在我的 UIViewController 中,我从 tableViewDelagate willDisplayCell
方法调用 [cell.youtubeView loadWithVideoId:f.videoID];
.问题是,当我的 tableView 中有许多单元格时,其中一些保持白色而不是 YouTube 内容!
I have a YTPlayerView inside of my subclass of UITableViewCell. In my UIViewController I call [cell.youtubeView loadWithVideoId:f.videoID];
from my tableViewDelagate willDisplayCell
method. The problem is that when I have many cells in my tableView some of them stay white instead of the YouTube content!
Youtube API 建议在重新使用 YTPlayerView 加载内容时打电话[cell.youtubeView cueVideoById:f.videoID startSeconds:0SuggestedQuality:kYTPlaybackQualityHighRes];
代替.不幸的是,这种方法根本不加载 YouTube 内容.
Youtube API recommends when reusing the YTPlayerView to load the content by calling
[cell.youtubeView cueVideoById:f.videoID startSeconds:0 suggestedQuality:kYTPlaybackQualityHighRes];
instead. Unfortunately, this method doesn't load YouTube content at all.
有人遇到过同样的问题吗?任何已知的解决方案?
Anybody came across the same issue? Any known solution?
我想在第一次加载内容时使用 loadWithVideoId
然后 cueVideoById
但这没有用.
I was thinking to load first time the content with loadWithVideoId
and then cueVideoById
but that didn't work.
推荐答案
Swift 3
我有同样的问题.我的问题是方法 load(withVideoId: videoId) 被多次调用(因为 cellForRow 在滚动时被调用了多次).
I had the same issue. My problem was that the method load(withVideoId: videoId) was called several times (because of the cellForRow called several times while scrolling).
我通过创建一个布尔值并确保 load(withVideoId: videoId) 只被调用一次来解决这个问题:
I solved this by creating a Boolean and making sure the load(withVideoId: videoId) is called only once :
1) 在单元格类中,创建一个全局布尔值
1) In the cell class, create a global Boolean
var isAlreadyPlaying : Bool = false
2)当您想播放视频时,我们会设置布尔值以避免多次播放:
2) When you want to play your video, we set our boolean to avoid playing it several times :
func loadVideo() {
//Making sure we are not playing the video several time
if isAlreadyPlaying == false {
//Creating vars (optional)
let playerVars = ["playsinline": 1, "autoplay": 1, "autohide": 1, "controls" : 1, "showinfo" : 0, "modestbranding" : 1, "rel" : 0]
// Launching the video
youtTubeView?.load(withVideoId: videoId, playerVars : playerVars)
// Force to not play the video again
isAlreadyPlaying = true
}
}
这篇关于UITableViewCell 内的 YTPlayerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UITableViewCell 内的 YTPlayerView
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01