public class ChangeVolume extends Activity {
MediaPlayer mPlayer;
AudioManager mAm;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.changevolume);
mAm = (AudioManager)getSystemService(AUDIO_SERVICE);
SeekBar seek = (SeekBar)findViewById(R.id.seekvolume);
seek.setMax(mAm.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
seek.setProgress(mAm.getStreamVolume(AudioManager.STREAM_MUSIC));
seek.setOnSeekBarChangeListener(mOnSeek);
}
SeekBar.OnSeekBarChangeListener mOnSeek =
new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
mAm.setStreamVolume(AudioManager.STREAM_MUSIC,
progress, 0);
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onStopTrackingTouch(SeekBar seekBar) {
}
};
public void onDestroy() {
super.onDestroy();
if (mPlayer != null) {
mPlayer.release();
mPlayer = null;
}
}
}
우선 seekbar를 통해서 볼륨조절은 가능합니다
하지만 스마트폰의 볼륨조절버튼을 누르면 seekbar의 상태변화가 없는데요..
당최 갈피를 못잡겠습니다.. 도와주세요!