【发布时间】:2016-02-17 10:18:02
【问题描述】:
我的 android 应用程序实现了 youtube SDK,当我点击播放时,它正在播放。当我旋转到横向时,它只播放纵向模式时间缓冲数据。我只有一种布局
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
setContentView(R.layout.activity_you_tube);
setTitle("YouTube Link");
//translucent();
if (savedInstanceState != null) {
onRestoreInstanceState(savedInstanceState);
youtubeURL = savedInstanceState.getString("YouTubeURL");
updateUI();
}
initeUI();
} catch (Exception e) {
Log.e(TAG, "onCreate " + e.getMessage());
}
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean wasRestored) {
try {
this.player = player;
progress.setVisibility(View.GONE);
youtubesubmit.setVisibility(View.VISIBLE);
metadataView.setVisibility(View.VISIBLE);
updateUI();
if (!wasRestored) {
player.cueVideo(youtubeID);
}
} catch (Exception e) {
Log.e(TAG, "onInitializationSuccess " + e.getMessage());
}
}
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
int controlFlags = player.getFullscreenControlFlags();
if (isChecked) {
// If you use the FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE, your activity's normal UI
// should never be laid out in landscape mode (since the video will be fullscreen whenever the
// activity is in landscape orientation). Therefore you should set the activity's requested
// orientation to portrait. Typically you would do this in your AndroidManifest.xml, we do it
// programmatically here since this activity demos fullscreen behavior both with and without
// this flag).
setRequestedOrientation(PORTRAIT_ORIENTATION);
controlFlags |= YouTubePlayer.FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE;
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
controlFlags &= ~YouTubePlayer.FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE;
}
player.setFullscreenControlFlags(controlFlags);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
int controlFlags = player.getFullscreenControlFlags();
try {
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
controlFlags &= ~YouTubePlayer.FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE;
player.setFullscreenControlFlags(controlFlags);
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
}
} catch (Exception e) {
Log.e(TAG, "onConfigurationChanged " + e.getMessage());
}
}
你能帮忙吗
【问题讨论】:
-
您的纵向模式和横向模式应该有不同的布局文件夹。您可以找到更多关于支持多屏的信息here。
标签: android youtube youtube-api