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.