Android的媒体播放器调节音量 [英] Android Mediaplayer adjust volume
问题描述
任何人都知道我怎么可以增加/点击音量键在手机的侧面降低从媒体播放器的声音的音量?我怎么能静音如果手机设置为静音模式?
code我使用的是:
MP = MediaPlayer.create(这一点,R.raw.sound);
mp.start();
我觉得这是你可能会感兴趣的内容:
1,增大/减小声音的音量:
链接在这里
块引用>基本上
覆盖
的的onkeydown
,然后调用mp.setVolumn(浮动leftVolume,浮动rightVolume);
2,关闭声音,如果手机设置为静音模式
块引用>AudioManager上午=(AudioManager)getSystemService(Context.AUDIO_SERVICE);开关(am.getRingerMode()){
案例AudioManager.RINGER_MODE_SILENT:
mp.setVolumn(0,0);
打破;
}Anyone know how can I increase/decrease the volume of the sound from mediaplayer by clicking on the volume button at the side of the phone? And how can I mute the sound if the phone was set to silent mode?
Code I'm using:
mp = MediaPlayer.create(this, R.raw.sound); mp.start();
解决方案I think this is what you might be interested in:
1, increase/decrease the volume of the sound: Link Here
Basically
Override
theonKeyDown
and then callmp.setVolumn(float leftVolume,float rightVolume);
2, mute the sound if the phone was set to silent mode
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE); switch (am.getRingerMode()) { case AudioManager.RINGER_MODE_SILENT: mp.setVolumn(0,0); break; }
这篇关于Android的媒体播放器调节音量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!