3

How can I set the volume of 2 simultaneously playing mediaplayer objects using a single seekbar?

when the seekbar goes to left the volume of one song should increase and volume of other song should decrease.

I tried using the mp.setVolume method for this purpose but no use. As far as I know, using AudioManager , the stream music is set. This means that if two songs are being played then both the songs would either have an increase in the volume or would have a decrease. Is there any other way? here's my code:

    @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                if(progress==progress--)
                {
                    int volume=volumeSeekbar.getMax()-progress;
                mp.setVolume(volume, volume);
                mp1.setVolume(progress,progress);
                //audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0);
                }
                }

Thanks in advance.

ank
  • 55
  • 1
  • 7
  • Show the code for implementing seekbar. How are you incrementing/decrementing your volume? – SoulRayder Jan 09 '14 at 09:35
  • it doesnt make any difference as mp.setVolume method does not work only. the volume neither increases nor decreases with the progress of seekbar. – ank Jan 09 '14 at 09:37
  • the volume of the mediaplayer object neither increases nor decreases along with the seekbar's progress. so its of no use. – ank Jan 09 '14 at 09:40

1 Answers1

0

To use seekbar to control volume in android:

Using SeekBar to Control Volume in android?

In this function given there,

@Override
            public void onProgressChanged(SeekBar arg0, int progress, boolean arg2) 
            {
                audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
                        progress, 0);
                //Here instead of playing with audioManager, play with your media player objects, by using mp.setvolume() function. Increase one, and decrease the other.
            }
        });

Here instead of playing with audioManager, play with your media player objects, by using something like

 mp1.setvolume(volume_index,volume_index);  
 mp2.setvolume(-volume_index,-volume_index);

Increase one, and decrease the other, and viceversa.

Note: You can also map progress to volume_index by checking how incrementally it increases and then doing the same for volume_index.

Community
  • 1
  • 1
SoulRayder
  • 5,072
  • 6
  • 47
  • 93