Basic functions of mobile AV 7--video player (4)

Source: Internet
Author: User
Tags gety

1. Tune the sound with Audiomanager

1_ get current volume and maximum volume

About setting the volume private int currentvolume;//current volume value private int currentmaxvolume;//current maximum volume private audiomanager am;am = ( Audiomanager) Getsystemservice (audio_service);     Currentvolume = Am.getstreamvolume (audiomanager.stream_music); currentmaxvolume = Am.getstreammaxvolume ( Audiomanager.stream_music);

2_ change the volume when dragging

Voice_seekbar.setonseekbarchangelistener (New Onseekbarchangelistener () {              @Override public       Void Onstoptrackingtouch (SeekBar SeekBar) {          senddelayedhidecontrolplayermessage ();       }              @Override public       void Onstarttrackingtouch (SeekBar SeekBar) {          removedelayedhidecontrolplayermessage ();       }              @Override public       void onprogresschanged (SeekBar SeekBar, int progress,            Boolean fromuser) {          if (fromuser) {            Updatevolume (progress);}}       ); * * Modify Volume Range 0~15 * @param progress2*/protected void updatevolume (int volume) {    Am.setstreamvolume ( Audiomanager.stream_music, volume, 0);    Voice_seekbar.setprogress (volume);       Currentvolume = volume;}

3_ Mute and non-muted

Case R.id.btn_voice:ismute =!ismute;updatevolume (currentvolume); break;/** * Modify Volume range 0~15 * @param progress2*/protected void Updatevolume (int volume) {if (Ismute) {am.setstreamvolume (audiomanager.stream_music, 0, 0); Voice_ Seekbar.setprogress (0);} Else{am.setstreamvolume (Audiomanager.stream_music, volume, 0); voice_seekbar.setprogress (volume);} Currentvolume = Volume;}
2. Swipe up and down on the screen to change the size of your voice
Private  Float starty;/** * Sliding area */private Float touchrang;/** * Current volume */private  int mvol; @Overridepublic Boolean Ontouchevent (motionevent event) {switch (event.getaction ()) {case motionevent.action_down://finger press the screen//1. Record related Values Starty = Event.gety (); Touchrang =math.min (ScreenWidth, screenheight);//screenheightmvol = Am.getstreamvolume ( Audiomanager.stream_music); handler.removemessages (Hide_mediacontrol); Break;case motionevent.action_move:// The finger moves//2 on the screen. came to the end of the coordinates of float EndY = Event.gety ();//3. calculated offset Float Distancey = starty-endy;//to change the sound = (sliding distance/total distance) * Max Volume float D Elta = (Distancey/touchrang) *maxvolume;//final sound = original sound + to change the sound of float volum  e = math.min (Math.max (mvol+delta,0), Maxvolume); if (Delta! = 0) {updatavolumeprogress ((int) volume);} Starty = Event.gety (); break;case motionevent.action_up://finger off screen handler.sendemptymessagedelayed (HIDE_ mediacontrol,5000); break;} Return Super.ontouchevent (event);}
3. Monitor to change sound size by phone sound
@Overridepublic boolean onKeyDown (int keycode, keyevent event) {    if (keycode = = Keyevent.keycode_volume_down) {        currentvolume--;        Updatavolumeprogress (currentvolume);        Handler.removemessages (Hide_mediacontrol);        Handler.sendemptymessagedelayed (Hide_mediacontrol,);        return true;    } else if (KeyCode ==keyevent.keycode_volume_up) {        currentvolume++;        Updatavolumeprogress (currentvolume);        Handler.removemessages (Hide_mediacontrol);        Handler.sendemptymessagedelayed (Hide_mediacontrol,);        return true;    }    

  

  

  

Basic functions of mobile AV 7--video player (4)

Related Article

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.