在平板电脑(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();
}
我究竟做错了什么???任何建议将不胜感激,因为我真的被困在这里。