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
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- UITextView 内容插图 2022-01-01
- URL编码Swift iOS 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01