YouTube播放器已在设备旋转和活动重新创建时发布。然后播放视频。节目 YouTube 播放器已发布。我不知道它在哪里发布。我已经将其设置为空销毁方法。
`mPlayer.loadVideo(videoId);`
//指向 YouTube 播放器发布
我的解决方案是在触发屏幕旋转时onSaveInstanceState(Bundle state)
通过YouTubePlayer getCurrentTimeMillis()
保存当前的播放时间,并从onRestoreInstanceState(Bundle state)
中获取时间。
示例代码为:
static final String CURRENT_PLAY_TIME = "current_play_time";
int current_time;
@Override
protected void onSaveInstanceState(Bundle state) {
super.onSaveInstanceState(state);
state.putInt(CURRENT_PLAY_TIME, youTubePlayer.getCurrentTimeMillis());
}
@Override
protected void onRestoreInstanceState(Bundle state) {
super.onRestoreInstanceState(state);
current_time = state.getInt(CURRENT_PLAY_TIME);
}
恢复当前播放时间后,让YouTubePlayer使用它加载视频。
youTubePlayer.loadVideo(VIDEO_ID, current_time);
希望对您有所帮助!
一个可能的解决方案是使您的应用程序垂直或水平永久
为此,请在清单中写入:
<android:screenOrientation="portrait"> //vertical
<android:screenOrientation="landscape"> //horizontal
I have found my Excelent solution..all going good with youtube player
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
if (mPlayer != null)
//Set YouTube Player here;
}
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
if (mPlayer != null)
//Set YouTube Player here;
}
}