leftAm = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
int maxVolume = leftAm.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int curVolume = leftAm.getStreamVolume(AudioManager.STREAM_MUSIC);
SeekBar volControl = (SeekBar)findViewById(R.id.leftVolume);
volControl.setMax(maxVolume);
volControl.setProgress(curVolume);
volControl.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
// TODO Auto-generated method stub
leftAm.setStreamVolume(AudioManager.STREAM_MUSIC, arg1, 0);
}
});
xml:
<SeekBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/volumebar"
android:max="100"
android:paddingBottom="10dip"/>