Android sliding scroll bar to adjust the volume, android scroll bar

Source: Internet
Author: User

Android sliding scroll bar to adjust the volume, android scroll bar

Use scroll bar sliding to control the volume:

Definition:

1 private SeekBar mseekBarvolume;

The following code is used:

1 // adjust the volume -- begin ------------------------- 2 // volume control, initialization Definition 3 mAudioManager = (AudioManager) getSystemService (Context. AUDIO_SERVICE); 4 // obtain the maximum volume of 5 int maxVolume = mAudioManager. getStreamMaxVolume (AudioManager. STREAM_MUSIC); 6 // get the current volume 7 syscurrenvolume = mAudioManager. getStreamVolume (AudioManager. STREAM_MUSIC); 8 9 mseekBarvolume = (SeekBar) findViewById (R. id. seekBar_volume); 10 // The maximum volume bound to the progress bar. The maximum volume is 11 mse. EkBarvolume. setMax (maxVolume); 12 // The progress bar is bound to the current volume of 13 mseekBarvolume. setProgress (syscurrenvolume); 14 15 // adjust the volume event 16 mseekBarvolume. setOnSeekBarChangeListener (new OnSeekBarChangeListener () {17 18 @ Override 19 public void onStopTrackingTouch (SeekBar seekBar) {20 // release event 21} 22 23 @ Override 24 public void onStartTrackingTouch (SeekBar seekBar) {25 // TODO Auto-generated method stub 26} 27 28 @ Overrid E 29 public void onProgressChanged (SeekBar seekBar, int progress, 30 boolean fromUser) {31 // TODO Auto-generated method stub 32 // get the current progress 33 int tmpInt = seekBar. getProgress (); 34 35 // when the progress is less than 1, set it to 1 to avoid being too small. 36 if (tmpInt <1) {37 tmpInt = 1; 38} 39 40 // adjust the brightness of 41 mAudioManager according to the current progress. setStreamVolume (AudioManager. STREAM_MUSIC, tmpInt, 0); 42} 43}); 44 // adjust the volume -- end -------------- 45 47} 48

 

Refer to the following code for implementation:

Android volume control adjustment (

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.