Android 用AudioManager类控制音量
2010-07-05 00:03:00 来源:WEB开发网viewHolder.myProgressBar=(ProgressBar)findViewById(R.id.myProgress);
viewHolder.audiomanage=(AudioManager)getSystemService(AUDIO_SERVICE);
}
//按钮 的单击事件
ImageButton btnListener(ImageButton b){
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.downButton:
viewHolder.audiomanage.adjustVolume(AudioManager.ADJUST_LOWER, 0);
volume=viewHolder.audiomanage.getStreamVolume(AudioManager.STREAM_RING);
viewHolder.myProgressBar.setProgress(volume);
mode=viewHolder.audiomanage.getRingerMode();
setImageState();
break;
case R.id.upButton:
viewHolder.audiomanage.adjustVolume(AudioManager.ADJUST_RAISE, 0);
volume=viewHolder.audiomanage.getStreamVolume(AudioManager.STREAM_RING);
viewHolder.myProgressBar.setProgress(volume);
mode=viewHolder.audiomanage.getRingerMode();
setImageState();
break;
case R.id.muteButton:
viewHolder.audiomanage.setRingerMode(AudioManager.RINGER_MODE_SILENT);
volume=viewHolder.audiomanage.getStreamVolume(AudioManager.STREAM_RING);
viewHolder.myProgressBar.setProgress(volume);
viewHolder.myImageView.setImageDrawable(getResources().getDrawable(R.drawable.mute));
break;
case R.id.normalButton:
viewHolder.audiomanage.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
volume=viewHolder.audiomanage.getStreamVolume(AudioManager.STREAM_RING);
viewHolder.myProgressBar.setProgress(volume);
viewHolder.myImageView.setImageDrawable(getResources().getDrawable(R.drawable.normal));
break;
case R.id.vibrateButton:
viewHolder.audiomanage.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
Tags:Android AudioManager 控制
编辑录入:coldstar [复制链接] [打 印]更多精彩
赞助商链接