本文整理汇总了Java中android.media.AudioManager.adjustStreamVolume方法的典型用法代码示例。如果您正苦于以下问题:Java AudioManager.adjustStreamVolume方法的具体用法?Java AudioManager.adjustStreamVolume怎么用?Java AudioManager.adjustStreamVolume使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.AudioManager
的用法示例。
在下文中一共展示了AudioManager.adjustStreamVolume方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onViewClicked
import android.media.AudioManager; //导入方法依赖的package包/类
@OnClick({R.id.volume_down, R.id.volume_up})
public void onViewClicked(View view) {
AudioManager audioManager = getAudioManager();
switch (view.getId()) {
case R.id.volume_down:
if (audioManager != null) {
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, 0);
}
break;
case R.id.volume_up:
if (audioManager != null) {
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, 0);
}
break;
}
}
示例2: ajustVol
import android.media.AudioManager; //导入方法依赖的package包/类
/**
* 调整音量
*
* @param increase true=增加百分之20 false=减少百分之20
*/
public String ajustVol(boolean increase, int progress) {
AudioManager mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
int currentVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
float max = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
currentVolume = (int) (currentVolume + max * (progress / 100.0f) * (increase ? 1 : -1));
if (currentVolume < 0)
currentVolume = 0;
else if (currentVolume > max)
currentVolume = (int) max;
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, currentVolume, 0);
//弹出系统媒体音量调节框
mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_SAME, AudioManager.FLAG_PLAY_SOUND
| AudioManager.FLAG_SHOW_UI);
NumberFormat nf = NumberFormat.getPercentInstance();
//返回数的整数部分所允许的最大位数
nf.setMaximumIntegerDigits(3);
//返回数的小数部分所允许的最大位数
// nf.setMaximumFractionDigits(2);
return nf.format(currentVolume / max);
}
示例3: onVoiceSettingInteraction
import android.media.AudioManager; //导入方法依赖的package包/类
@Override
protected boolean onVoiceSettingInteraction(Intent intent) {
if (intent.hasExtra(EXTRA_DO_NOT_DISTURB_MODE_ENABLED)) {
int minutes = intent.getIntExtra(EXTRA_DO_NOT_DISTURB_MODE_MINUTES, -1);
Condition condition = null;
int mode = Global.ZEN_MODE_OFF;
if (intent.getBooleanExtra(EXTRA_DO_NOT_DISTURB_MODE_ENABLED, false)) {
if (minutes > 0) {
condition = ZenModeConfig.toTimeCondition(this, minutes, UserHandle.myUserId());
}
mode = Global.ZEN_MODE_ALARMS;
}
setZenModeConfig(mode, condition);
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
if (audioManager != null) {
// Show the current Zen Mode setting.
audioManager.adjustStreamVolume(AudioManager.STREAM_NOTIFICATION,
AudioManager.ADJUST_SAME,
AudioManager.FLAG_SHOW_UI);
}
notifySuccess(getChangeSummary(mode, minutes));
} else {
Log.v(TAG, "Missing extra android.provider.Settings.EXTRA_DO_NOT_DISTURB_MODE_ENABLED");
finish();
}
return false;
}
示例4: changeMediaVolume
import android.media.AudioManager; //导入方法依赖的package包/类
@Override
public void changeMediaVolume(int percent) {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
mCurrentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int volume = (int) ((percent / 100.0) * maxVolume + 0.5);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_SAME, AudioManager.FLAG_PLAY_SOUND
| AudioManager.FLAG_SHOW_UI);
}
示例5: volumeUp
import android.media.AudioManager; //导入方法依赖的package包/类
private void volumeUp() {
AudioManager audio = (AudioManager) MBApp.getApp().getSystemService(Context.AUDIO_SERVICE);
audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
/*
scheduleMediaKeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_UP, 0);
scheduleMediaKeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_UP, 100);
*/
}
示例6: volumeDown
import android.media.AudioManager; //导入方法依赖的package包/类
private void volumeDown() {
AudioManager audio = (AudioManager) MBApp.getApp().getSystemService(Context.AUDIO_SERVICE);
audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);
/*
scheduleMediaKeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_DOWN, 0);
scheduleMediaKeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_DOWN, 100);
*/
}
示例7: doInBackground
import android.media.AudioManager; //导入方法依赖的package包/类
@Override
protected String doInBackground(String... params) {
AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
return "Executed";
}