Audiomanager Sound Management usage in Android (Android) development

Source: Internet
Author: User

The Audiomanager class is located on Android. Media package, this class provides access to control volume and sound mode operation

The following are the Audiomanager ways to set the sound mode and adjust the sound size.

How to get the Sound manager:

The code is as follows Copy Code

Audiomanager Audiomanager = (audiomanager) getsystemservice (Audio_service);

The Main method inside:

A, set the sound mode

The code is as follows Copy Code

Sound mode
Audiomanager.setringermode (Audiomanager.ringer_mode_normal);
Mute mode
Audiomanager.setringermode (audiomanager.ringer_mode_silent);
Vibration mode
Audiomanager.setringermode (audiomanager.ringer_mode_vibrate);


B, adjust the sound size

The code is as follows Copy Code

Reduce sound Volume
Audiomanager.adjustvolume (audiomanager.adjust_lower, 0);
Increase the volume of sound
Audiomanager.adjustvolume (audiomanager.adjust_raise, 0);

(when the first parameter passed in is Audiomanager.adjust_lower, you can turn the volume down one unit, and when you pass in the Audiomanager.adjust_raise, turn the volume up one unit.) )


GetMode () Get audio mode

Getringermode () Get ring Vibration mode

Audiomanager

public void Setstreammute (int streamtype, Boolean state)


Mute or not mute the audio stream.

Mute commands are protected from client process death: If the process dies with an active mute request on the stream, the stream is automatically muted.

For a given stream, the mute request is cumulative: Audiomanager receives several mute requests from one or more clients, and the mute is Shireu only if the same number of cancellation requests is received.

For a better user experience, the program must remove the muted stream from the OnPause (), if appropriate, mute again in Onresume ()


This method can be used only for platform-wide management applications or primary telephony applications that replace audio settings.


Parameters

Streamtype to Mute/cancel the quiet stream.

State Requests Mute Status: If true, mute, and if false, suppress mute.

If you use the mode associated with the phone vibration, remember to add permissions. Android.permission.VIBRATE Oh!

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.