我正在使用 YouTubePlayerView 加载视频。视频播放成功,但是当屏幕旋转时,它停止播放。我该如何克服这个问题?这可能是一件简单的事情。我用谷歌搜索但没有得到帮助,但你的需要帮助...下面是我的代码。
代码:
youTubePlayerView=findViewById(R.id.youtube_view);
onInitializedListener=new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayers=youTubePlayer;
youTubePlayers.loadVideo("9ZaEPeaucIU");
youTubePlayers.setFullscreenControlFlags(FULLSCREEN_FLAG_CONTROL_ORIENTATION);
youTubePlayers.setOnFullscreenListener(onFullscreenListener);
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
}
};
onFullscreenListener=new YouTubePlayer.OnFullscreenListener() {
@Override
public void onFullscreen(boolean b) {
if (b){
time=youTubePlayers.getCurrentTimeMillis();
}
}
};
play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
youTubePlayerView.initialize("AI&*$^$^$3634HxbhVM@#$%%^%&%$",onInitializedListener);
}
});
布局:
<com.google.android.youtube.player.YouTubePlayerView
android:layout_width="match_parent"
android:layout_height="250dp"
android:id="@+id/youtube_view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
</com.google.android.youtube.player.YouTubePlayerView>