我在UITableViewCell的子类中有一个YTPlayerView。在我的UIViewController中,我从我的tableViewDelagate willDisplayCell方法调用[cell.youtubeView loadWithVideoId:f.videoID];。问题是,当我的tableView中有许多单元格时,其中一些单元格保持白色,而不是YouTube内容!
当重用YTPlayerView来加载内容时,通过调用[cell.youtubeView cueVideoById:f.videoID startSeconds:0 suggestedQuality:kYTPlaybackQualityHighRes];来执行Youtube API recommends。不幸的是,这个方法根本不加载YouTube内容。
有没有人遇到过同样的问题?有什么已知的解决方案吗?
我想先用loadWithVideoId加载内容,然后用cueVideoById加载,但没有成功。
发布于 2015-05-03 02:51:45
我在UIColectionViewCell实例中使用YTPlayerView实例时遇到了这个问题。最终,我必须要做的是停止didEndDisplayingCell ([self.playerView stopVideo])中的视频。然后在prepareForReuse (或可选的cellForRowAtIndexPath)中,空出你的playerView,然后在cellForRowAtIndexPath中重新初始化播放器并通过id加载视频。
发布于 2015-09-25 06:57:50
我在UICollectionView中使用了YTPlayerView (与您的情况类似)。
在我的例子中,当YTPlayerView在reused UICollectionViewCell中绘制时,它变黑了(在第一个初始化的单元上正确加载)。
YTPlayerView变黑是因为-loadWithVideoId:playerVars:在第一个调用的方法完成之前被调用了两次。
我检查了白色 YTPlayerView是用于未加载的视频,所以我建议在某个地方检查-loadWithVideoId:或类似的调用正确的方法。
发布于 2017-07-12 21:04:46
Swift 3
我也有同样的问题。我的问题是方法load(withVideoId: videoId)被调用了几次(因为cellForRow在滚动时被调用了几次)。
我通过创建一个布尔值并确保load(withVideoId: videoId)只被调用一次来解决这个问题:
1)在单元格类中,创建一个全局布尔值
var isAlreadyPlaying : Bool = false2)当你想要播放你的视频时,我们设置了我们的布尔值来避免多次播放:
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
}
}https://stackoverflow.com/questions/23345576
复制相似问题