开发学院手机开发Android 开发 Android 用AudioManager类控制音量 阅读

Android 用AudioManager类控制音量

 2010-07-05 00:03:00 来源:WEB开发网   
核心提示:viewHolder.myProgressBar=(ProgressBar)findViewById(R.id.myProgress);viewHolder.audiomanage=(AudioManager)getSystemService(AUDIO_SERVICE);}//按钮 的单击事件ImageButton

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);

上一页  1 2 3 4 5 6  下一页

Tags:Android AudioManager 控制

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接