Android volume acquisition-something confusing

Source: Internet
Author: User

Today, we have a requirement in the project to use seekbar to control the volume.


I thought it was a very simple thing (it was indeed a very simple thing), but at the beginning it could not achieve what I wanted. After some modifications and searches, the solution was finally solved. In the process of solving this problem, I also found some shortcomings in my understanding of Android.


So, let's discuss it. Let's talk about the volume now.


In the Android system, there is a sound system volume, call volume, ringtone volume, Music volume, and prompt sound volume (I thought there was only one volume in Android: system volume (incomplete self-taught .....)).


Next we will introduce the methods for obtaining these volumes one by one.


To obtain these volumes, you need an audiomanager class that controls the volume together. (You can just click here on your own)


Audiomanager = (audiomanager) getsystemservice (context. audio_service );


Int Max; // The maximum volume.

Int current; // current volume


// System volume

Max = maudiomanager. getstreammaxvolume (audiomanager. stream_system );

Current = maudiomanager. getstreamvolume (audiomanager. stream_system );


// Call volume

Int max = aM. getstreammaxvolume (audiomanager. stream_voice_call );

Int current = aM. getstreamvolume (audiomanager. stream_voice_call );


// Ringtone volume

Max = maudiomanager. getstreammaxvolume (audiomanager. stream_ring );

Current = maudiomanager. getstreamvolume (audiomanager. stream_ring );


// Music volume

Max = maudiomanager. getstreammaxvolume (audiomanager. stream_music );

Current = maudiomanager. getstreamvolume (audiomanager. stream_music );


// Sound volume prompt

Max = aM. getstreammaxvolume (audiomanager. stream_alarm );

Current = Sm. getstreamvolume (audiomanager. stream_alarm );

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.