I'm using the Youtube Android Player API as outlined here: https://developers.google.com/youtube/android/player/
However, I can't get more than one video into my activity at once. I tried simply putting two YouTubePlayerViews into the activity like so:
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/view_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/view_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
MainActivity.java
package com.example.multidemo;
import android.os.Bundle;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayer.Provider;
import com.google.android.youtube.player.YouTubePlayerView;
public class MainActivity extends YouTubeBaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
((YouTubePlayerView) findViewById(R.id.view_one)).initialize("API key", new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(Provider arg0, YouTubePlayer arg1, boolean arg2) {
arg1.cueVideo("RpwoN_XlN6Y");
}
@Override
public void onInitializationFailure(Provider arg0, YouTubeInitializationResult arg1) {
}
});
((YouTubePlayerView) findViewById(R.id.view_two)).initialize("API key", new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(Provider arg0, YouTubePlayer arg1, boolean arg2) {
arg1.cueVideo("jkk2mMq2x8E");
}
@Override
public void onInitializationFailure(Provider arg0, YouTubeInitializationResult arg1) {
}
});
}
}
When I try this, the first view just comes up black, while the second video loads. If I comment out the code in onCreate() for the second video, then just the first video will load.
Is there any way to get multiple YouTubePlayerViews into the same activity?