Basic functions of mobile AV 6--video player (3)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.