4

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

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);
}
}
4

2 回答 2

11

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

于 2013-06-17T20:26:52.780 回答
0

您甚至不需要一次加载两个视频,只需使用函数 cueVideos(),并在其中放入一个列表字符串变量,它就会一个接一个地播放视频。非常方便:)

于 2013-12-05T19:52:13.877 回答