Android-在ListView中使用Youtube Player API播放Youtube视频 [英] Android - Playing Youtube Videos using Youtube Player API in ListView

查看:106
本文介绍了Android-在ListView中使用Youtube Player API播放Youtube视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试过使用WebView在ListView中显示Youtube视频,发生的事情是当我向下滚动屏幕并返回到该视频所在的单元格时,视频消失了,这意味着WebView不会将其中包含视频的WebView呈现回.因此,我尝试使用YoutubePlayerAPI,但发现很难理解如何使用YoutubePlayerAPI插入这些视频.

I have tried using WebViews to display Youtube Videos in ListView, what happens is when i scroll off screen and back to the cell the Video was located the Video disappears meaning that the WebView does not render back the WebView with the Video in it. So i tried using YoutubePlayerAPI but i am finding it difficult to understand how i can insert these Videos using the YoutubePlayerAPI.

有人可以建议吗?

我尝试在ArrayAdapter中使用YoutubePlayerView,但出现Inflate错误,我也创建了YoutubeBaseActivity和YoutubeFragment,但无法理解如何获取布局或ui以在ListView单元格中显示这些视频.

I have tried using YoutubePlayerView in my ArrayAdapter but i get Inflate errors, i have also created YoutubeBaseActivity and YoutubeFragment but cant understand how i get the layout or ui to display these videos in my ListView Cells.

推荐答案

我是怎么做到的

此处下载youtube android SDK,然后获取jar文件并将其复制到您应用程序的libs文件夹中.

Download the youtube android SDK from here then get the jar file and copy it to libs folder on your app.

在gradle.build中的依赖项下的依赖项中输入此内容

Enter this in dependency in gradle.build under dependencies

compile files('libs/YouTubeAndroidPlayerApi.jar')

Syc并构建.

创建一个扩展YoutubeBaseActivity的活动,如下所示,并实现YoutubePlayer.OnInitializedListener,如下所示.覆盖接口上的方法. Android Studio可以帮助您做到这一点.

Create an activity that extends YoutubeBaseActivity like below and implement the YoutubePlayer.OnInitializedListener as shown below. Override the methods on the interace. Android studio can help you do this.

public class Display extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {

然后,在成功加载后,

@Override
public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean b) {
    if (!b) {
        player.cueVideo(videoID);
    }
}

这将加载youtube播放器,然后您使用API​​播放

This will load the youtube player and you play on the API

快乐的编码,很抱歉迟到了

Happy coding, sorry am late

这篇关于Android-在ListView中使用Youtube Player API播放Youtube视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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