当前位置: 首页>>代码示例>>Java>>正文


Java AudioManager.adjustStreamVolume方法代码示例

本文整理汇总了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;
    }
}
 
开发者ID:h4h13,项目名称:RetroMusicPlayer,代码行数:17,代码来源:VolumeFragment.java

示例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);
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:29,代码来源:MusicPlayProcessor.java

示例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;
}
 
开发者ID:ric96,项目名称:lineagex86,代码行数:30,代码来源:ZenModeVoiceActivity.java

示例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);
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:12,代码来源:VoiceMediator.java

示例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);
    */
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:10,代码来源:RemoteControlPlugin.java

示例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);
      */
  }
 
开发者ID:Samsung,项目名称:microbit,代码行数:10,代码来源:RemoteControlPlugin.java

示例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";
  }
 
开发者ID:mwsrc,项目名称:Dendroid-HTTP-RAT,代码行数:7,代码来源:MyService.java


注:本文中的android.media.AudioManager.adjustStreamVolume方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。