我使用:
mediaPlayer.setVideoScalingMode(android.media.MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT);
但它不起作用,我想让视频适合屏幕。
最佳答案
VIDEO_SCALING_MODE_SCALE_TO_FIT
是默认值,因此调用
mediaPlayer.setVideoScalingMode(android.media.MediaPlayer
.VIDEO_SCALING_MODE_SCALE_TO_FIT);
没有什么区别。
http://developer.android.com/reference/android/media/MediaCodec.html#setVideoScalingMode(int)
The default is "scale to fit".
例如,获取以下基于 MediaCodec 的播放器:
https://github.com/google/ExoPlayer
并通过在 MediaCodecVideoTrackRenderer.java 中设置 VIDEO_SCALING_MODE_SCALE_TO_FIT
或 VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING
进行实验
再加一点。
您想要完成的任务可以通过以下方式完成:
在 SurfaceView 上实现 onMeasure。
获取视频大小。
调用 setMeasuredDimension 使用不同的值,具体取决于您是否想要拉伸(stretch)、调整或裁剪视频:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = getDefaultSize(videoWidth, widthMeasureSpec);
int height = getDefaultSize(videoHeight, heightMeasureSpec);
// Do not change w & h for screen fill
setMeasuredDimension(width, height);
// Experiment by changing width & height compared to the video size
// for different results
}
关于Android媒体播放器设置视频缩放模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27274911/