【问题标题】:Issue when playing video in local and url path在本地和 url 路径中播放视频时出现问题
【发布时间】:2013-04-25 21:06:54
【问题描述】:

我在 VideoView 中播放视频

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

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

【问题讨论】:

  • 您使用的服务器是什么?您确定您的服务器没有对视频文件进行任何类型的编码或调整大小。通过比较原始文件和从服务器下载的文件来检查文件的尺寸。

标签: android


【解决方案1】:

看看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);
}

【讨论】:

  • 谢谢。请告诉我们需要为“player”和“surfaceViewFrame”传递哪个引用。
  • 播放器是你的MediaPlayer对象,surfaceViewFrame是SurfaceView
  • 请给我发送任何编码以在 Surfaceview 中播放视频。现在我在 videoview 中播放
猜你喜欢
  • 1970-01-01
  • 2017-09-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-18
  • 2014-01-04
  • 1970-01-01
相关资源
最近更新 更多