UITableViewCell 内的 YTPlayerView

YTPlayerView inside UITableViewCell(UITableViewCell 内的 YTPlayerView)

本文介绍了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

基础教程推荐