android使用videoview 全屏方法,Android如何更改默认的VideoView/MediaPlayer全屏?

我目前正在VideoView中播放视频(.mp4文件,这两种android平板电脑都能很好地工作)。首先我使用VideoView,但设备(EKEN M003S)全屏播放视频,而不是在VideoView中设置宽度和高度272 x 153 dp。所以我试图让一个扩展的VideoView类来覆盖onMeasure()和changeVideoSize()。就像这样:Android如何更改默认的VideoView/MediaPlayer全屏?

public class EkenVideoView extends VideoView {

@Override

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

//Log.i("@@@@", "onMeasure");

int width = getDefaultSize(mVideoWidth, widthMeasureSpec);

int height = getDefaultSize(mVideoHeight, heightMeasureSpec);

if (mVideoWidth > 0 && mVideoHeight > 0) {

if (mVideoWidth * height > width * mVideoHeight) {

//Log.i("@@@", "image too tall, correcting");

height = width * mVideoHeight/mVideoWidth;

} else if (mVideoWidth * height < width * mVideoHeight) {

//Log.i("@@@", "image too wide, correcting");

width = height * mVideoWidth/mVideoHeight;

} else {

//Log.i("@@@", "aspect ratio is correct: " +

//width+"/"+height+"="+

//mVideoWidth+"/"+mVideoHeight);

}

}

if (screenMode == DisplayMode.ORIGINAL) {

if (mVideoWidth > 0 && mVideoHeight > 0) {

if (mVideoWidth * height > width * mVideoHeight) {

// video height exceeds screen, shrink it

height = width * mVideoHeight/mVideoWidth;

} else if (mVideoWidth * height < width * mVideoHeight) {

// video width exceeds screen, shrink it

width = height * mVideoWidth/mVideoHeight;

} else {

// aspect ratio is correct

}

}

}

else if (screenMode == DisplayMode.FULL_SCREEN) {

// just use the default screen width and screen height

}

else if (screenMode == DisplayMode.ZOOM) {

// zoom video

if (mVideoWidth > 0 && mVideoHeight > 0 && mVideoWidth < width) {

height = mVideoHeight * width/mVideoWidth;

}

}

//Log.i("@@@@@@@@@@", "setting size: " + width + 'x' + height);

setMeasuredDimension(272, 153);

}

public void changeVideoSize(int width, int height)

{

mVideoWidth = width;

mVideoHeight = height;

// not sure whether it is useful or not but safe to do so

getHolder().setFixedSize(272, 153);

requestLayout();

invalidate(); // very important, so that onMeasure will be triggered

}

我进宽272,高153迫使宽度和高度的MP4视频是该大小的,但EKEN M003S继续以全屏模式播放视频。因此,当我运行该应用程序时,一切正常,并且视频以全屏方式在所有其他视图下方的图层中播放,使活动在其下方的视频中变得透明。

除了EKEN M003S之外,我确定某些设备也有功能强制视频在默认情况下全屏播放,并且还有一种方法可以覆盖默认设置。如果有办法,请教我如何去做。谢谢。

+0

“我确定某些设备也具有强制视频在默认情况下全屏播放的功能” - 没有合法的设置Android Market上。这不会通过市场的兼容性测试。因此,如果您确定自己的分析是正确的,那么您需要联系制造商,并询问他们如何解决他们的Android不兼容问题。 –