0

我的媒体播放器 AudioManager 有问题。当我通过搜索栏减小音量时,我会减小,但是当我确实增加进度时,它不会在相同状态下增加音量..请帮我解决我的问题..提前谢谢...

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/100.0f),(progress/100.0f));
    }
  }
});

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/100.0f),(progress/100.0f));
    }
  }
});
4

1 回答 1

0

此代码有效

     audioManager = (AudioManager) this.getSystemService(this.AUDIO_SERVICE);
    seekBar = (SeekBar) findViewById(R.id.seekBar1);
    seekBar.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC));



    seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

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

        }

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

        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {
            // TODO Auto-generated method stub

            audioManager.setStreamVolume(audioManager.STREAM_MUSIC, progress, 0);

        }
    });
于 2012-07-20T11:14:47.403 回答