Android的媒体播放器调节音量 [英] Android Mediaplayer adjust volume

查看:744
本文介绍了Android的媒体播放器调节音量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道我怎么可以增加/点击音量键在手机的侧面降低从媒体播放器的声音的音量?我怎么能静音如果手机设置为静音模式?

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 the onKeyDown and then call mp.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆