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;

阅读 6.9k
1 个回答

AudioManager.STREAM_SYSTEM 换成AudioManager.STREAM_MUSIC?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题