Android volume adjustment and media volume page

Source: Internet
Author: User

 

When the user adjusts the volume, the system's media volume interface is displayed, which is out of line with the design style of the project.

Therefore, it is necessary to adjust the volume and display the custom media volume interface.

 

1) Adjust the Music volume

Private audiomanager = NULL; // audio

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

Increase or decrease the volume:

Audiomanager. adjuststreamvolume (audiomanager. stream_music,
Audiomanager. adjust_raise, audiomanager. flag_play_sound
| Audiomanager. flag_show_ui );

Audiomanager. adjuststreamvolume (audiomanager. stream_music,
Audiomanager. adjust_lower, audiomanager. flag_play_sound
| Audiomanager. flag_show_ui );

 

Audiomanager. flag_show_ui displays the media volume page. Override the onkeydown method:

@ Override
Public Boolean onkeydown (INT keycode, keyevent event ){
Switch (keycode ){
Case keyevent. keycode_volume_up:
Audiomanager. adjuststreamvolume (audiomanager. stream_music,
Audiomanager. adjust_raise, audiomanager. flag_play_sound );
Return true;
Case keyevent. keycode_volume_down:
Audiomanager. adjuststreamvolume (audiomanager. stream_music,
Audiomanager. adjust_lower, audiomanager. flag_play_sound );
Return true;
Default:
Break;
}
Return super. onkeydown (keycode, event );
}

You can also display the custom media volume page.

 

2) custom media volume page

You need to obtain the current volume. The method is as follows:

Private void getv (){
// Call volume
Int max = audiomanager
. Getstreammaxvolume (audiomanager. stream_voice_call );
Int current = audiomanager
. Getstreamvolume (audiomanager. stream_voice_call );
Log. D ("vioce_call", "Max:" + MAX + "Current:" + current );

// System volume
Max = audiomanager. getstreammaxvolume (audiomanager. stream_system );
Current = audiomanager. getstreamvolume (audiomanager. stream_system );
Log. D ("system", "Max:" + MAX + "Current:" + current );

// Ringtone volume
Max = audiomanager. getstreammaxvolume (audiomanager. stream_ring );
Current = audiomanager. getstreamvolume (audiomanager. stream_ring );
Log. D ("ring", "Max:" + MAX + "Current:" + current );

// Music volume
Max = audiomanager. getstreammaxvolume (audiomanager. stream_music );
Current = audiomanager. getstreamvolume (audiomanager. stream_music );
Log. D ("Music", "Max:" + MAX + "Current:" + current );

// Sound volume prompt
Max = audiomanager. getstreammaxvolume (audiomanager. stream_alarm );
Current = audiomanager. getstreamvolume (audiomanager. stream_alarm );
Log. D ("alarm", "Max:" + MAX + "Current:" + current );
}

To get the current volume and the maximum volume, you can draw a media volume interface that is consistent with your own application style.

 

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.