我做了一个无线电播放器,搜索栏没有调高或调低音量,我不知道为什么会这样。
final SeekBar volume=(SeekBar)findViewById(R.id.bar);
audMan = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
int maxVolume = audMan.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int curVolume = audMan.getStreamVolume(AudioManager.STREAM_MUSIC);
mplayer = new MediaPlayer();
mplayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
volume.setMax(maxVolume);
volume.setProgress(curVolume);
song_title=(TextView)findViewById(R.id.txt);
seekBarValue=(TextView)findViewById(R.id.textView1);
Value=(TextView)findViewById(R.id.seekbarvalue);
song_title.setTextColor(Color.CYAN);
seekBarValue.setTextColor(Color.CYAN);
Value.setTextColor(Color.CYAN);
volume.setProgress(0);
volume.incrementProgressBy(5);
volume.setMax(100);
volume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
{
public void onStopTrackingTouch(SeekBar bar)
{
int value = bar.getProgress(); // the value of the seekBar progress
}
public void onStartTrackingTouch(SeekBar bar)
{
}
public void onProgressChanged(SeekBar bar,
int paramInt, boolean paramBoolean)
{
seekBarValue.setText("" + paramInt + "%"); // here in textView the percent will be shown
}
});发布于 2013-01-15 19:00:17
你必须在某一时刻调用AudioManger.setStreamVolume() ...
public void onProgressChanged(SeekBar bar,
int paramInt, boolean paramBoolean)
{
seekBarValue.setText("" + paramInt + "%"); // here in textView the percent will be shown
AudioManager audioManager = (AudioManager)Context.getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,paramInt,flags);
}flags只是要使用的标志。例如,AudioManager.FLAG_SHOW_UI可以用来显示带有音量的Toast。如果你不需要标志,你可以传递0。
https://stackoverflow.com/questions/14336082
复制相似问题