I use:
mediaPlayer.setVideoScalingMode(android.media.MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT);
but it is not working i want to fit video to screen.
VIDEO_SCALING_MODE_SCALE_TO_FIT
is the value by default, so calling to
mediaPlayer.setVideoScalingMode(android.media.MediaPlayer
.VIDEO_SCALING_MODE_SCALE_TO_FIT);
will make no difference.
http://developer.android.com/reference/android/media/MediaCodec.html#setVideoScalingMode(int)
The default is "scale to fit".
As example, grab the following MediaCodec based player:
https://github.com/google/ExoPlayer
and experiment by setting VIDEO_SCALING_MODE_SCALE_TO_FIT
or VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING
in MediaCodecVideoTrackRenderer.java
Adding a bit more.
What you are trying to accomplish can be done the following way:
Implement the onMeasure on your SurfaceView.
Get the video size.
Call to setMeasuredDimension with different values depending if you want to Stretch, Fit or Crop your video:
@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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With