打兩個或兩個以上的Youtube播放器採用的是Android的Youtube API,我想在我的應用程序的主要活動打兩個視頻,而無需使用我們有這個Multiple Youtube players in one activity同樣的問題片段,但沒有接受的解答,請幫助我們。的Android的YouTube API中的一個主要活動
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"
>
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/video1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/video2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
MainActivity.java
package com.apps.you;
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.video1)).initialize("AIzaSyBmb9Yqu9vEBXjNOrBmZZ__6s12RH5RSv0", new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(Provider provider1, YouTubePlayer player1, boolean restored1) {
if (!restored1) {
player1.cueVideo("Daa38ruXHxE");
}
}
@Override
public void onInitializationFailure(Provider provider1, YouTubeInitializationResult result1) {
}
});
((YouTubePlayerView) findViewById(R.id.video2)).initialize("AIzaSyBmb9Yqu9vEBXjNOrBmZZ__6s12RH5RSv0", new YouTubePlayer.OnInitializedListener() {
public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean restored) {
if (!restored) {
player.loadVideo("ctQAPiojDKE");
}
}
public void onInitializationFailure(Provider provider, YouTubeInitializationResult result) {
}
});
}
}
的問題,這是唯一的一個視頻是玩到了最後,視頻1初始化被他們稱之爲同
的視頻2初始化overrriden.initialize(new YouTubePlayer.OnInitializedListener(){});
由此:
((YouTubePlayerView) findViewById(R.id.video1)).initialize(new
YouTubePlayer.OnInitializedListener(){});
((YouTubePlayerView) findViewById(R.id.video2)).initialize(new
YouTubePlayer.OnInitializedListener(){});
你解決了這個問題嗎? –
Eliran Tutia據我記得,我只能在每個活動中一次播放和初始化一個視頻,甚至使用片段。 – Cristiana214