I've created a DJ program with a mediaplayer on each side of the screen(like in the picture below)
The seekbar between those two whenever moved should increase volume of one mediaplayer and decrease the other mediaplayer's volume respectively. When I drag it very slowly it works perfectly, the problem is when I move it faster. When dragged faster the volumes doesn't always decrease to the end or doesn't decrease at all, at super speed the volume doesn't change at all. Here is the code:
private void initiateSeekBar()
{
try
{
volumeSeekbar = (SeekBar)findViewById(R.id.seekBar);
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
//volumeSeekbar.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
//volumeSeekbar.setProgress(audioManager.getStreamVolume(AudioManager.STREAM_MUSIC));
final int initVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
final int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,maxVolume, 0);
volumeSeekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
@Override
public void onStopTrackingTouch(SeekBar arg0)
{
}
@Override
public void onStartTrackingTouch(SeekBar arg0)
{
}
@Override
public void onProgressChanged(SeekBar arg0, int progress, boolean arg2)
{
float volume = (float) (1 - (Math.log(100 - progress) / Math.log(100)));
//audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0);
if (volume <= 0.05) {
volume = 0;
}
System.out.println("\nVolume: \n" + volume);
if (mediaplayerLeft != null) {
mediaplayerLeft.setVolume(1 -volume, 1 - volume);
}
if (mediaplayerRight != null) {
mediaplayerRight.setVolume(volume, volume);
}
}
});
}
catch (Exception e)
{
e.printStackTrace();
}
}
Why is that happening? Is that how seekbar works or is it a problem with my code?