To resize the video, I expanded the VideoView class, redefined onMeasure as follows:

 @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension(widthMeasureSpec, heightMeasureSpec); } 

On the emulator, the video size changes, on the device, only the size of VideoView itself VideoView , the video fits into it without changing the aspect ratio.

PS It turns out that even on one console, everything changes as it should, but on the other (necessary) it does not want, and the version of the android on them is the same - 4.0.4.

PPS Simple code:

 public class MainActivity extends Activity { final public String TAG="VVActivity"; MediaPlayer mMediaPlayer; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SurfaceView surface = (SurfaceView)findViewById(R.id.surface); SurfaceHolder.Callback callback = new SurfaceHolder.Callback(){ @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {} @Override public void surfaceCreated(SurfaceHolder holder) { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setDisplay(holder); try { mMediaPlayer.setDataSource("/mnt/sdcard/file.mpg"); mMediaPlayer.prepare(); mMediaPlayer.start(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } @Override public void surfaceDestroyed(SurfaceHolder holder) { }}; surface.getHolder().addCallback(callback); } } 

It also works on one device, and on the other the aspect ratio does not change. So it's not about VideoView . I tried on videos of different resolution and even format, all the same.

  • Maybe it's in the video files themselves? - DroidAlex
  • If so, what could be the matter? The stream is played in standard h.264. - anutakay
  • I would use ffmpeg to convert the video to a lower resolution, which is suitable for a mobile device (based on a resolution of 320x480 at least). If it's not a VideoView, it means in the files themselves. - DroidAlex

1 answer 1

VideoView (or SurfaceView for MediaPlayer). If you want to maintain the aspect ratio.

Thus, if the video fits completely into the current VideoView size, then it will not scale further.

It turns out that even on one console, everything changes as it should, but on the other (necessary) it does not want, and the version of the android on them is the same - 4.0.4.

I suspect they have a different screen resolution.

  • That's exactly what while maintaining proportions. I also need to keep the proportions. If you make a small VideoView, for example 200dpx200dp, that is, such that the video clearly does not fit into it, the video decreases, but the aspect ratio does not change. - anutakay
  • one
    See blog.kasenlam.com/2012/02/… . Or you might need a MediaPlayer that has a setVideoScalingMode method. - falstaf
  • on the link: Sorry, it doesn’t exist. ((I would not like to use MediaPlayer separately. Maybe this mode can be used inside the VideoView class or an heir from it ... - anutakay
  • I apologize, accidentally hit the dot at the end of the link. Corrected. And why do not you like the use of MediaPlayer? - falstaf
  • Thanks for the link. As I understand it, the advice in this article comes down to the fact that you need to use RelativeLayout and tie the edges of the video to the edges of this layout. I have already done so)) MediaPlayer would not want to use it because then you need to rewrite all the work from the video without obvious advantages. - anutakay