Mobile Audio Eighth day control the video playback page above and below the controller layout disappear and hidden

Source: Internet
Author: User

By default, when the player plays a video, the upper and lower control bars of the video page are hidden, the video is displayed after you click it, and then you click Hide, long press the video and pause, and then long press to play. also resolves a small bug that disappears and hides

Code is hosted on the code cloud, can be downloaded to see, address:

Https://git.oschina.net/joy_yuan/MobilePlayer

First, implement the display and hide the control bar

To recognize gestures like click, double Tap, and long press on your phone, Android has a special class to handle, namely gesturedetector---gesture recognizer. To use the gesture recognizer, you have the following 3 steps

1, the declaration recognizer, the instantiation of the recognizer

2, rewrite the recognizer's click, double-tap, long-press method

3, will click on the screen generated callback event, as a parameter passed to the recognizer's Ontouchevent (event), and then in the 2nd step to deal with a specific Click event callback method


When the control bar is displayed, if there is no action for three seconds, the control bar is automatically hidden and is implemented using the handler delay Send message mechanism.


The

Specific code is as follows:

private gesturedetector dector;  //  gesture Recognizer Dector=new gesturedetector (this,new  gesturedetector.simpleongesturelistener () {    /**     *   Long press the triggered callback function      *  @param  e     */      @Override     public void onlongpress (motionevent e)  {         super.onlongpress (e);         startandpause ();         toast.maketext ( Systemvideoplayer.this, "Long press the Screen", Toast.length_short). Show ();     }    /**      *  Double-click the triggered function      *  @param  e      *  @return      */     @Override      public boolean ondoubletap (MotiOnevent e)  {        //toast.maketext (SystemVideoPlayer.this, "Double-click on screen", Toast.length_short). Show ();         ismediacontrollershow ();         return super.ondoubletap (e);     }     /**     *  Click the triggered function      * @ param e     *  @return      */      @Override     public boolean onsingletapconfirmed (motionevent e)   {        //toast.maketext (Systemvideoplayer.this, "clicked Screen", Toast.LENGTH_ Short). Show ();         handler.removemessages (Hidevideo);         ismediacontrollershow ();         if   (isshow) { &NBSp;          handler.sendemptymessagedelayed (HIDEVIDEO,3000) ;        }        return  Super.onsingletapconfirmed (e);     });//use Ontouchevent to pass event events to the gesture recognizer, Otherwise, the gesture recognizer's callback method cannot be triggered @overridepublic boolean ontouchevent (motionevent event)  {     dector.ontouchevent (event);     return super.ontouchevent (event);}

In this case, the visiable of the controller bar is displayed or hidden by clicking, double-clicking, and long-pressing.


Second, to resolve the resulting bug

When we click on the video, display the control bar, and then drag the Seekbar progress bar, three seconds later, the control bar will disappear, this is whether we drag the control bar or can control the video playback progress. This kind of user experience is poor.

The solution is that in Seekbar change monitoring, when the user taps Seekbar, the handler removemessages (Hiddenvideo) is removed to remove the message from the hidden control bar sent. In the callback method after the user leaves Seekbar, resend the message of the hidden control bar, which is delayed by three seconds, with the following code:

/** *  the progress bar in the Video play box drag the change of monitoring  */class VideoOnSeekBarChangeListener implements  seekbar.onseekbarchangelistener {    /**     *  Trigger      *  @param  seekbar     * @ when finger is sliding on seekBar param progress     *  @param  fromUser    Is the seekbar change caused by artificial sliding, the system auto-swipe will also cause this callback method      */     @Override      public void onprogresschanged (seekbar seekbar, int progress,  Boolean fromuser)  {        if  (fromuser) {             videoview.seekto (progress);    // You can view the MediaPlayer declaration cycle diagram, which has this method.         }    }    /**      *  trigger      *  @param when clicked SeekBar  seekbar     */      @Override     public void onstarttrackingtouch (SeekBar  seekbar)  {        //Stop handler messages to hide the control bar when the hand is clicked SeekBar          handler.removemessages (Hidevideo);    }     /**     *  Trigger      * @ when leaving Seekbar param seekbar     */     @Override      Public void onstoptrackingtouch (Seekbar seekbar)  {         //when hand leaves Seekbar, trigger handler message to hide control bar          Handler.sendemptymessagedelayed (hidevideo,3000);     }}


Similarly, when the control bar is displayed, whether it is the click Stop, Play button, or click the next, the previous button, you have to implement the above logic, that is, first remove the message, and then resend the deferred message

@Overridepublic  void onclick (view v)  {    if  ( v ==  btnVoice )  {        // Handle clicks  for btnvoice    } else if  ( v == switchPlayer )  {        // handle clicks for switchplayer     } else if  ( v == btExit )  {         // Handle clicks for btExit    Exit          finish ();    } else if  ( v ==  btVideoPre )  {        // Handle clicks  for btvideopre   Play previous video         if  (medialist!=null &&medialist.sizE () >0) {            position-=1;             if  (position<=0) {                 position=medialist.size () -1;             }             mediaitem mediaitem=medialist.get (position);             tvname.settext (Mediaitem.getname ());             videoview.setvideopath (Mediaitem.getdata ());         }else if  (uri!=null) {             tvname.settext (Uri.tostring ());             videoview.setVideouri (URI);         }    } else if   ( v == btVideoStartPause )  {        //  Handle clicks for btVideoStartPause   play pause and start          startandpause ();    } else if  ( v ==  btnext )  {        // Handle clicks for  btnext    Play Next      if  (Medialist!=null&&medialist.size () >0) {         position+=1;          if  (Position>=medialist.size ()) {              position=0;         }        &nbsP;     mediaitem mediaitem = medialist.get (position);              tvname.settext (MediaItem.getName ());              videoview.setvideopath ( Mediaitem.getdata ());     }else if  (uri!=null) {          //set the previous Next button to Gray           Tvname.settext (Uri.tostring ());          videoview.setvideouri (URI );          btnext.setenabled (false);          btnext.setbackgroundresource (R.drawable.btn_next_gray);      }    } else if  ( v == btVideoSwitchScreen )   {&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;//&NBsp handle clicks for btvideoswitchscreen    }     Handler.removemessages (Hidevideo);     handler.sendemptymessagedelayed (HIDEVIDEO,3000);}


This article is from the "Yuangushi" blog, make sure to keep this source http://cm0425.blog.51cto.com/10819451/1949131

Mobile Audio Eighth day control the video playback page above and below the controller layout disappear and hidden

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.