我在 VideoView 中播放视频
当我从 SD 卡播放时,它全屏显示正确的宽度和高度。当我尝试从服务器播放时,视频宽度更小并且视频被重新调整大小。
如何以原始尺寸和全屏播放视频?
我在 VideoView 中播放视频
当我从 SD 卡播放时,它全屏显示正确的宽度和高度。当我尝试从服务器播放时,视频宽度更小并且视频被重新调整大小。
如何以原始尺寸和全屏播放视频?
查看文档并实现 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);
}