Android应用中的全屏视频

时间:2013-11-22 09:16:21

标签: android video android-fullscreen

在平板电脑上运行时(在Android 4.2.2上),我的Android应用中的视频无法全屏播放。我试图在我的三星手机上运行该应用程序(尝试Android 4.2和4.3),此处视频全屏显示。

我的视频活动有以下onCreate():

@Override public void onCreate(Bundle savedInstanceState) {
    mInstance = this;
    super.onCreate(savedInstanceState);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN|
            WindowManager.LayoutParams.TYPE_APPLICATION_PANEL|
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
            WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);

    mSurfaceView = new SurfaceView(this);
    setContentView(mSurfaceView);

    mSurfaceHolder = mSurfaceView.getHolder();
    mSurfaceHolder.addCallback(this);
    mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    Intent intent = getIntent();
    mVideoPath = intent.getStringExtra("VIDEO_PATH");
    try {
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setOnBufferingUpdateListener(this);
        mMediaPlayer.setOnCompletionListener(this);
        mMediaPlayer.setOnPreparedListener(this);
        mMediaPlayer.setOnVideoSizeChangedListener(this);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mMediaPlayer.setScreenOnWhilePlaying (true);
    }
    catch (Exception e) { e.printStackTrace(); }

}

...以及onVIdeoSizeChanged():

public void onVideoSizeChanged(MediaPlayer player, int width, int height) {
    Log.v(TAG, "MediaPlayer: onVideoSizeChanged called");
    if (width == 0 || height == 0) {
        Log.e(TAG, "invalid video width(" + width + ") or height(" + height + ")");
        return;
    }

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(width, height, 0x11); //Gravity.CENTER

    mSurfaceView.setLayoutParams(params);
    mSurfaceView.requestLayout();
}

我做错了什么???任何建议都将受到赞赏,因为我真的被困在这里。

1 个答案:

答案 0 :(得分:1)

不知道这是否特定于我正在使用的设备,但我不得不更改以下文件/ sys / class / screen_mode,这使我的视频处于全屏模式。