我目前正在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之外,我確定某些設備也有功能強制視頻在默認情況下全屏播放,並且還有一種方法可以覆蓋默認設置。如果有辦法,請教我如何去做。謝謝。
「我確定某些設備也具有強制視頻在默認情況下全屏播放的功能」 - 沒有合法的設置Android Market上。這不會通過市場的兼容性測試。因此,如果您確定自己的分析是正確的,那麼您需要聯繫製造商,並詢問他們如何解決他們的Android不兼容問題。 – CommonsWare