【发布时间】:2013-04-25 21:06:54
【问题描述】:
我在 VideoView 中播放视频
当我从 SD 卡播放时,它全屏显示正确的宽度和高度。当我尝试从服务器播放时,视频宽度更小并且视频被重新调整大小。
如何以原始尺寸和全屏播放视频?
【问题讨论】:
-
您使用的服务器是什么?您确定您的服务器没有对视频文件进行任何类型的编码或调整大小。通过比较原始文件和从服务器下载的文件来检查文件的尺寸。
标签: android
我在 VideoView 中播放视频
当我从 SD 卡播放时,它全屏显示正确的宽度和高度。当我尝试从服务器播放时,视频宽度更小并且视频被重新调整大小。
如何以原始尺寸和全屏播放视频?
【问题讨论】:
标签: android
看看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);
}
【讨论】: