如果您将手机纵向放置,然后单击(YouTubePlayerView
的全屏按钮),则稍稍摇动手机就可以轻松将其取回(关闭全屏)
YouTube官方应用正常运行:在将手机保持纵向的状态下,按全屏按钮时,如果稍微摇动手机,它仍将保持全屏横屏模式。而且,如果您将手机旋转到横向,然后又回到纵向,那么它将关闭全屏显示(应该如此)
所以我想在官方的YouTube应用中实现相同的行为
我尝试为YouTubePlayer
设置不同的全屏标记,但是它什么都没有影响
活动清单
<activity
android:label="@string/playerview_demo_name"
android:name=".PlayerViewDemoActivity"
android:screenOrientation="user"
android:configChanges="orientation|screenSize|keyboardHidden">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
活动Java
public class PlayerViewDemoActivity extends YouTubeFailureRecoveryActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.playerview);
YouTubePlayerView youTubeView = findViewById(R.id.youtube_view);
youTubeView.initialize(DeveloperKey.DEVELOPER_KEY, this);
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
boolean wasRestored) {
if (!wasRestored) {
player.cueVideo("wKJ9KzGQq0w");
/*
FULLSCREEN_FLAG_CONTROL_ORIENTATION;
FULLSCREEN_FLAG_CONTROL_SYSTEM_UI;
FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE;
FULLSCREEN_FLAG_CUSTOM_LAYOUT;
*/
player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION);
}
@Override
protected YouTubePlayer.Provider getYouTubePlayerProvider() {
return (YouTubePlayerView) findViewById(R.id.youtube_view);
}
}
Mb YouTube应用程序执行以下操作:
按下全屏按钮后,它们将进行设置(仅当程序电话的显示方向为纵向模式时)
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
然后他们使用设备传感器检测大致方向(如果您以纵向/横向握住手机)-Detect Android device orientation (NOT screen orientation)
当您将手机旋转到横向时,手机会设置
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);