Question

I have a problem to get video in my android app to play in full screen when running on a tablet (on Android 4.2.2). I have tried to run the app on my Samsung phone (tried both Android 4.2 and 4.3) and here the video is in full screen.

My video activity has the following 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(); }

}

... And the following 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();
}

What am I doing wrong??? Any suggestions will be appreciated, as I am really stuck here.

Was it helpful?

Solution

Don't know if this is specific for the device I'm using but I had to change the following file /sys/class/screen_mode, which put my video in full screen mode.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top