Reputation: 6522
I'm creating an app where I have three MediaPlayer objects in my activity. Ler's call them mp1, mp2 and mp3.
I am playing all of the 3 MediaPlayers at the same time, so the user should be able to set how loud each of the sounds should be.
This is how I tried to do it:
mp1.setVolume(volume1, 100);
mp2.setVolume(volume2, 100);
mp2.setVolume(volume3, 100);
volume1, volume2 and volume3 are variables set by the user using a SeekBar. I'm not sure how setVolume() works, so I was guessing that the first number should be how loud it is and second should be the max value.
However, this isn't working at all, no matter what those values are, the sound plays the same every time. Could someone tell me how can I control the volume of each 3 MediaPlayers?
Upvotes: 0
Views: 1161
Reputation: 1871
According to the documentation, you need to pass through your volume variable as both parameters in the setVolume() method. That way, both the left and right channel volumes are set. Furthermore, this value should be between 0.0 and 1.0, not 0-100 (based on what I see in your sample code). However, you could easily convert an integer between 0 and 100 to between 0.0 and 1.0 by dividing it as a float:
float volume1F = (float) volume1/100;
Then, you could do this to set the volume:
mp1.setVolume(volume1F, volume1F);
Upvotes: 3