这是我用于控制两个搜索栏以在媒体播放器中设置音量控制以同时播放两个声音的代码。但是在seekbar的进度变化时声音会打开和关闭,在进度变化时不会频繁增加或减少音量。我哪里错了?
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);
}
}
});