Android How to change default VideoView / MediaPlayer full screen?

I'm currently working on playing a video (.mp4 file which works well in both two android tablets) in VideoView. First I used VideoView but the device (EKEN M003S) played the video in full screen, not within the VideoView which I set both width and height by 272 x 153 dp. So I tried to make an extended class of VideoView to override onMeasure() and changeVideoSize(). Like this:

    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
}

I entered width 272 and height 153 to force width and height of the .mp4 video to be of that size, but EKEN M003S continues to play video in full screen mode. So when I run the app, everything works fine and the video plays in full screen on a layer below all other Views, making the Activity translucent with the video beneath it.

Other than EKEN M003S, I'm sure that some devices also have functions to force video to play in full screen by default, and also there is a way to override that default setting. If there is a way, please teach me how to do it. Thank you.


http://clseto.mysinablog.com/index.php?op=ViewArticle&articleId=2992625

I've tested this code on an Asus TF 101 (1280x800 res) and had the video running at a 640x480. Try setting the dimensions in your XML file and in your changeVideoSize() method, try setting screenMode = DisplayMode.ORIGINAL

链接地址: http://www.djcxy.com/p/46490.html

上一篇: Android:如何在播放过程中旋转VideoView

下一篇: Android如何更改默认的VideoView / MediaPlayer全屏?