如何分别控制MediaPlayer音量和SoundPool音量?

时间:2015-01-01 19:33:54

标签: android android-mediaplayer media-player soundpool android-seekbar

我正在开发一款游戏,我正在使用MediaPlayer音乐和soundpool音效

我创建了一个配置菜单,其中seekbar用于控制音乐(mediaplayer)音量,另一个seekbar用于控制音效(soundpool)音量

如何在不干扰两个卷的情况下实现这一目标?

2 个答案:

答案 0 :(得分:0)

Instead of trying to set global volume values for MediaPlayer and SoundPool, how about you set the volume for each sound separately?

SoundPool supports volume settings on [play()](https://developer.android.com/reference/android/media/SoundPool.html#play(int, float, float, int, int, float)) and also during playback with [setVolume()](https://developer.android.com/reference/android/media/SoundPool.html#setVolume(int, float, float))

MediaPlayer, on the other hand has a separate [setVolume()](https://developer.android.com/reference/android/media/MediaPlayer.html#setVolume(float, float)) for you to use.

答案 1 :(得分:0)

我猜你有两个变量,音乐和效果;分别。

播放音乐时只需将 musicVolume 传递给 pool.play(),播放音效时传递 effectVolume

pool.play(musicId, musicVolume, musicVolume, 1, 0, 1);

pool.play(effectId, effectVolume, effectVolume, 1, 0, 1);