1. Custom Videoview
1_ Custom videoview-Increase the Set video size method
public class Videoview extends Android.widget.VideoView { /** * Android system when looking for this class in a more XML layout, and instantiate it with this constructor method * * @param context * @param attrs * /Public Videoview (context context, AttributeSet attrs) { Super (context, attrs); } Public Videoview (Context context) { super (context); } @Override protected void onmeasure (int widthmeasurespec, int heightmeasurespec) {// super.onmeasure ( Widthmeasurespec, Heightmeasurespec); Setmeasureddimension (Widthmeasurespec, Heightmeasurespec); } /** * Set the width and height of the video screen * @param videowidth * @param videoheight * /public void setvideosize (int videowidth, int videoheight) { viewgroup.layoutparams layoutparams =getlayoutparams (); Layoutparams.width = Videowidth; Layoutparams.height = videoheight; Setlayoutparams (Layoutparams); }}
2_ Get screen height and width method
In the player
WM = (WindowManager) getsystemservice (window_service); screenwidth = Wm.getdefaultdisplay (). getwidth (); screenHeight = Wm.getdefaultdisplay (). GetHeight ();D isplaymetrics displaymetrics = new Displaymetrics (); This.getwindowmanager (). Getdefaultdisplay (). Getmetrics (displaymetrics); screenwidth = Displaymetrics.widthpixels;screenheight = Displaymetrics.heightpixels;
3_ Video Default and fullscreen
One play up, in the Ready set video playback default
/** * true Full screen * flase default */private Boolean isfullscreen = false;/** * Video fullscreen and default * @param type*/public void setvideotype (int t ype) {switch (type) {case SCREEN_FULL:videoview.setVideoSize (screenwidth, screenheight); isfullscreen = True;btn_ Switch_screen.setbackgroundresource (r.drawable.btn_screen_dafult_selector); break;case screen_defult://Video's wide int Mvideowidth = videowidth;//video High int mvideoheight = videoheight;//screen width int width = screenwidth;//screen width int height = Screenheig Ht;if (mvideowidth > 0 && mvideoheight > 0) {if (Mvideowidth * height > Width * mvideoheight) {//LOG.I ("@@@", "image too tall, correcting"); height = width * mvideoheight/mvideowidth;} else if (mvideowidth * Height < width * mvideoheight) {//log.i ("@@@", "image too wide, correcting"); width = height * Mvideowidth/mvideoheight;} else {//log.i ("@@@", "aspect ratio is correct:" +//width+ "/" +height+ "=" +//mvideowidth+ "/" +mvideoheight ";}} Videoview.setvideosize (width, height); btn_switch_screen.setbackgroundreSource (r.drawable.btn_screen_full_selector); isfullscreen = False;break; }}
4_ screen keeps the screen unlocked
The settings screen does not lock screen GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_ KEEP_SCREEN_ON);
5_ switch Playback mode when the button is clicked
Case R.id.btn_switch_screen:if (isfullscreen) { setvideotype (screen_defualt);} else{ Setvideotype (screen_full);} Break
Basic functions of mobile AV 6--video player (3)