Android 活动中的多个 YouTube 视频 [英] Android Multiple YouTube Videos in Activity

查看:19
本文介绍了Android 活动中的多个 YouTube 视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将两个 YouTubePlayerViews 放在一起.他们都出现了,但似乎只有一个提示任何视频.第二个 (youTubeView2) 是黑色的.没有错误.知道我做错了什么吗?

I am trying to have two YouTubePlayerViews on top of each other. They both show up, but only one seems to cue any videos. The second one (youTubeView2) is just black. No errors. Any idea what I am doing wrong?

JSONObject data;
JSONArray array;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.playerview_demo);

YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
youTubeView.initialize(DeveloperKey.DEVELOPER_KEY, this);
YouTubePlayerView youTubeView2 = (YouTubePlayerView) findViewById(R.id.youtube_view2);
youTubeView2.initialize(DeveloperKey.DEVELOPER_KEY, this);



//JSONObject json = getJSONfromURL("http://gdata.youtube.com/feeds/api/users/rhettandlink2/uploads?v=2&alt=jsonc");

try{
    JSONObject json = new RetreiveFeedTask().execute().get();
    data = json.getJSONObject("data");
    array = data.getJSONArray("items");
    //Log.d("num vids", ""+id[1].toString());
    for (int i = 0; i < array.length(); i++) {
        final JSONObject item = array.getJSONObject(i);
        final JSONObject player = item.getJSONObject("player");
        final String url = player.getString("default");
        // The url is that of the video to be played
        //Log.d("GMM Videos", url.toString());


        final String id = item.getString("id");


    }}
catch(JSONException e) {
    Log.e("GMM Videos", "Error parsing data "+e.toString());
 } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  } catch (ExecutionException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }



}

@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
  boolean wasRestored) {
if (!wasRestored) {
    List<String> myList = new ArrayList<String>();
    try{
    for (int i = 0; i < array.length(); i++) {
        final JSONObject item = array.getJSONObject(i);
        final JSONObject jplayer = item.getJSONObject("player");
        final String url = jplayer.getString("default");
        // The url is that of the video to be played
        //Log.d("GMM Videos", url.toString());


        final String id = item.getString("id");
        //allVideos[i] = player.cueVideo(id);
        myList.add(id);

    }}
    catch(JSONException e) {
        Log.e("GMM Videos", "Error parsing data "+e.toString());
   }



  player.cueVideos(myList);
}
}

推荐答案

我的理解是这是预期的行为.(它可能与硬件加速视频播放相关的限制有关,也可能没有.)您所看到的是 YouTube Android 播放器 SDK 强制执行一次一个视频的限制.

My understanding is that this is the intended behavior. (It may or may not have something to do with limitations associated with hardware accelerated video playback.) What you're seeing is the YouTube Android Player SDK enforcing a one-video-at-a-time limitation.

这篇关于Android 活动中的多个 YouTube 视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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