在本地和URL路径中播放视频时出现问题

时间:2013-04-25 12:19:15

标签: android

我在VideoView中播放视频

当我从SD卡播放时,它在全屏显示正确的宽度和高度。当我尝试从服务器播放时,视频宽度较小,视频会重新调整大小。

如何以原始尺寸和全屏播放视频?

1 个答案:

答案 0 :(得分:0)

查看documentation并实现onPrepared方法,如下面的代码:

//prepare the video
public void onPrepared(MediaPlayer mp) {        
    progressBarWait.setVisibility(View.GONE);

    //First get the size of the video
    int videoWidth = player.getVideoWidth();
    int videoHeight = player.getVideoHeight();
    float videoProportion = (float) videoWidth / (float) videoHeight;  

    //get the size of the screen
    int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
    int screenHeight = getWindowManager().getDefaultDisplay().getHeight();
    float screenProportion = (float) screenWidth / (float) screenHeight;

    //Adjust
    LayoutParams lp = surfaceViewFrame.getLayoutParams();
    if (videoProportion > screenProportion) {
        lp.width = screenWidth;
        lp.height = (int) ((float) screenWidth / videoProportion);
    } else {
        lp.width = (int) (videoProportion * (float) screenHeight);
        lp.height = screenHeight;
    }
    surfaceViewFrame.setLayoutParams(lp);

    if (!player.isPlaying()) {
        player.start();         
    }
    surfaceViewFrame.setClickable(true);
}