首页 > Android,静音或振动模式下如何使用SoundPool播放声音,而且可调节?

Android,静音或振动模式下如何使用SoundPool播放声音,而且可调节?

正在开发的项目中播放声音使用的是SoundPool,当手机在静音或振动模式下则播放不出声音。
SoundPool中调用play方法时传入的参数volume获得方法如下:
AudioManager mgr = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_SYSTEM);
float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_SYSTEM);
float volume = streamVolumeCurrent/streamVolumeMax;
return volume;


AudioManager.STREAM_SYSTEM 换成AudioManager.STREAM_MUSIC?

【热门文章】
【热门文章】