Audiomanager class: Adjust the system various volume

Source: Internet
Author: User

:

method Parsing: Increase/Decrease volume value
publicvoidadjustStreamVolume(intintint flags)
set the volume value
publicvoidsetStreamVolume(intintint flags)
Parameter Introduction

Streamtype is the type of volume you need to adjust, which can be:
Stream_alarm Alarm
Stream_music Music playback is media volume
Stream_notification window at the top of the status bar NOTIFICATION,
Stream_ring Ringtones
Stream_system system
Stream_voice_call Call
STREAM_DTMF dual tone Multi-frequency

direction is the direction of adjustment, increasing or decreasing, which can be:
Adjust_lower lowering the volume
Adjust_raise Raise the Volume
The adjust_same remains the same, which is used primarily to show the current volume to the user

Flags is a number of additional parameters that describe only two common
Flag_play_sound playing sound when you adjust the volume
FLAG_SHOW_UI Display the volume bar when adjusting

Index is the volume value to set, type int

Sample Code
 Public  class sunactivity extends appcompatactivity implements SeekBar . Onseekbarchangelistener {    Private intVoice_type;PrivateSeekBar Sb_media, sb_calling, Sb_system, Sb_clock;PrivateAudiomanager Audiomanager;Private intStartPoint;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_sun);        Audiomanager = (Audiomanager) getsystemservice (Context.audio_service);        Sb_media = (SeekBar) Findviewbyid (R.id.sb_media);        sb_calling = (SeekBar) Findviewbyid (r.id.sb_ring);        Sb_system = (SeekBar) Findviewbyid (R.id.sb_system); Sb_clock = (SeekBar) Findviewbyid (r.id.sb_alarm);//For Seekbar effect is obvious, the volume value is multiplied by 10 displaySb_media.setprogress (Audiomanager.getstreamvolume (audiomanager.stream_music) *Ten); Sb_calling.setprogress (Audiomanager.getstreamvolume (audiomanager.stream_ring) *Ten); Sb_system.setprogress (Audiomanager.getstreamvolume (audiomanager.stream_system) *Ten); Sb_clock.setprogress (Audiomanager.getstreamvolume (audiomanager.stream_alarm) *Ten); Sb_media.setonseekbarchangelistener ( This); Sb_calling.setonseekbarchangelistener ( This); Sb_system.setonseekbarchangelistener ( This); Sb_clock.setonseekbarchangelistener ( This); }@Override     Public void onprogresschanged(SeekBar SeekBar,intProgressBooleanFromuser) {}@Override     Public void Onstarttrackingtouch(SeekBar SeekBar)    {startPoint = Seekbar.getprogress (); }@Override     Public void Onstoptrackingtouch(SeekBar SeekBar) {Switch(Seekbar.getid ()) { CaseR.id.sb_media:voice_type = Audiomanager.stream_music; Break; CaseR.id.sb_ring:voice_type = audiomanager.stream_ring; Break; CaseR.id.sb_system:voice_type = Audiomanager.stream_system; Break; CaseR.id.sb_alarm:voice_type = Audiomanager.stream_alarm; Break; }//if (seekbar.getprogress () > StartPoint) {//Boost volume//Audiomanager.adjuststreamvolume (Voice_type, audiomanager.adjust_raise, 0);//} else {//Decrease volume//Audiomanager.adjuststreamvolume (Voice_type, audiomanager.adjust_lower, 0);//        }Audiomanager.setstreamvolume (Voice_type, seekbar.getprogress ()/Ten, audiomanager.flag_show_ui); }}
Partial Layout Code
    <linearlayout  android: Layout_width  = "match_parent"  android:layout_ Height  = "wrap_content"  android:gravity  = "center_vertical"  android:orientation  = "horizontal"  android:padding  = "20DP" ;         <textview  android:layout _width  = "wrap_content"  android:layout_height  = "wrap_content"  android:layout_marginright< /span>= "10DP"  android:background  = "@drawable/shape_text"  android:padding  =" 3DP " android:text  =" media " android:textcolor  = "#ffffff" />         <SeekBarandroid:id= "@+id/sb_media"android:layout_width="Match_ Parent "android:layout_height=" wrap_content " />                                        </linearlayout>

Audiomanager class: Adjust the system various volume

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.