UITableViewCell 中的 YTPlayerView [英] YTPlayerView inside UITableViewCell

查看:20
本文介绍了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:0RecommendedQuality: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) 在cell类中,创建一个全局布尔值

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆