You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

安卓视频播放器手动全屏时方向传感器误判问题求助

Fixing Orientation Mismatch When Triggering Fullscreen Manually

Hey there, let's work through this frustrating orientation bug you're dealing with! The core problem here is that your code is relying on the system's orientation reading— which gets messed up by the sensor in that specific (90,0,90) phone pose—when the user manually triggers fullscreen. We need to prioritize the user's explicit action over wonky sensor input in this scenario.

Key Issues in Your Current Code

  • The check for activity.getResources().getConfiguration().orientation is picking up the sensor's incorrect portrait reading when your phone is in that specific tilted state.
  • The fixed 4-second delay to switch back to sensor mode is arbitrary and can cause unexpected orientation shifts while the user is still in fullscreen.

Solutions to Implement

1. Prioritize User Intent Over Sensor Readings

When the user manually clicks the fullscreen button (isFromButtonClick is true), ignore the system's current orientation entirely. Instead, switch direction based purely on the user's action—this bypasses the sensor's temporary misjudgment.

2. Adjust Sensor Auto-Rotation Recovery

Instead of a fixed delay, only restore sensor-based rotation when the user explicitly exits fullscreen. This ensures the player doesn't switch back to portrait unexpectedly while the user is watching in fullscreen.

Modified Code Example

@Override 
public void onFullScreen(Boolean isFromButtonClick) { 
    // Handle manual button clicks first—user intent takes priority
    if (isFromButtonClick) {
        if (!isFullScreen) {
            // User wants to enter fullscreen: force landscape lock
            isFullScreen = true;
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            mediaController.updateFullScreen();
            loadRecommendations();
        } else {
            // User wants to exit fullscreen: force portrait lock
            isFullScreen = false;
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            mediaController.updateFullScreen();
        }
    } else {
        // For non-manual triggers (e.g., auto-fullscreen on video start), keep original logic
        int currentOrientation = activity.getResources().getConfiguration().orientation;
        if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) {
            isFullScreen = true;
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            mediaController.updateFullScreen();
            loadRecommendations();
        } else {
            isFullScreen = false;
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            mediaController.updateFullScreen();
        }
    }

    // Restore sensor rotation only when exiting fullscreen (if auto-rotation is enabled)
    if (!isFullScreen && Settings.System.getInt(activity.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 1) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
    }
}

Additional Tips

  • If you want fullscreen to stay locked in landscape (allowing left/right rotation but no portrait), use SCREEN_ORIENTATION_SENSOR_LANDSCAPE instead of SCREEN_ORIENTATION_LANDSCAPE.
  • Test edge cases with different phone orientations to make sure the manual fullscreen trigger always behaves as expected, overriding any sensor anomalies.

内容的提问来源于stack exchange,提问作者pallavi richhariya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:55:41