Monday, May 21, 2012

Media Player Error

This is my code for controlling two seekbars to set volume control in media player for two simultaneously playing sound. But the sound is turned on and off on the progress change of seekbar, it does not increase or decrease of volume frequently on progress change. Where am I wrong?



audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);

int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);

volume2 = (SeekBar)findViewById(R.id.volbar2);
volume1 = (SeekBar)findViewById(R.id.volbar);


volume1.setMax(maxVolume);
volume2.setMax(maxVolume);
volume1.setProgress(curVolume);
volume2.setProgress(curVolume);

volume1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

@Override
public void onStopTrackingTouch(SeekBar seekBar) {


}
@Override
public void onStartTrackingTouch(SeekBar arg0) {

}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean arg2) {

if(seekBar.equals(volume1)){

mediaPlayer.setVolume(progress,progress);

Toast.makeText(getApplicationContext(), ""+progress+progress, 1).show();

}

}
});

volume2.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub

}

public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub

}

public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
// TODO Auto-generated method stub
if(seekBar.equals(volume2)){
mediaPlayer2.setVolume(progress,progress);
}

}
});




No comments:

Post a Comment