Onpreparedlistener Mediaplayeronpreparedlistener =NewOnpreparedlistener () {@Override Public voidonprepared (MediaPlayer arg0) {//first get the width and height of video intVwidth =mediaplayer.getvideowidth (); intVheight =mediaplayer.getvideoheight (); //The parent container of the LinearLayout android:orientation= "vertical" must beLinearLayout LinearLayout =(LinearLayout) Findviewbyid (R.id.layoutplay); intLW =linearlayout.getwidth (); intLH =linearlayout.getheight (); if(Vwidth > LW | | vheight >LH) { //Zoom if the width or height of the video exceeds the size of the current screen floatWratio = (float) Vwidth/(float) LW; floatHratio = (float) Vheight/(float) LH; //Select the big one to zoom in floatRatio =Math.max (Wratio, hratio); Vwidth= (int) Math.ceil (float) Vwidth/ratio); Vheight= (int) Math.ceil (float) Vheight/ratio); //Set layout parameters for SurfaceviewLinearlayout.layoutparams lp=Newlinearlayout.layoutparams (Vwidth, vheight); Lp.gravity=Gravity.center; SURFACEVIEW.SETLAYOUTPARAMS (LP); } //and start playing the videoMediaplayer.start (); } };
Play video in Android Surfaceview play at the original proportions of the video