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


Java AudioManager.setStreamVolume方法代码示例

本文整理汇总了Java中android.media.AudioManager.setStreamVolume方法的典型用法代码示例。如果您正苦于以下问题:Java AudioManager.setStreamVolume方法的具体用法?Java AudioManager.setStreamVolume怎么用?Java AudioManager.setStreamVolume使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.media.AudioManager的用法示例。


在下文中一共展示了AudioManager.setStreamVolume方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validateState

import android.media.AudioManager; //导入方法依赖的package包/类
private void validateState(AudioManager manager) {

		int ringer = manager.getRingerMode();
		
		if (ringer != AudioManager.RINGER_MODE_SILENT 
				&& ringer != AudioManager.RINGER_MODE_VIBRATE) {
			
			// if volume is zero set it to medium
			int volume = manager.getStreamVolume(AudioManager.STREAM_RING);
			if (volume == 0) {
				manager.setStreamVolume(AudioManager.STREAM_RING, 4, 0);
				manager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 4, 0);
			}
		}
		
		// send internal volume changed notification
		mActivity.sendBroadcast(new Intent(Constants.ACTION_VOLUME_UPDATED));
	}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:19,代码来源:RingerSettingHandler.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: switchSpeaker

import android.media.AudioManager; //导入方法依赖的package包/类
/**
 * 扬声器开关
 * @param context
 * @param enableSpeaker 是否打开扬声器,true:打开,false:关闭
 */
public static void switchSpeaker(Context context, boolean enableSpeaker) {
    try {
        AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        audioManager.setMode(AudioManager.ROUTE_SPEAKER);
        int currVolume = audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
        if (enableSpeaker) {
            //setSpeakerphoneOn() only work when audio mode set to MODE_IN_CALL.
            audioManager.setMode(AudioManager.MODE_IN_CALL);
            audioManager.setSpeakerphoneOn(true);
            audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL,
                    audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL),
                    AudioManager.STREAM_VOICE_CALL);
        } else {
            audioManager.setSpeakerphoneOn(false);
            audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, currVolume,
                    AudioManager.STREAM_VOICE_CALL);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:sundevin,项目名称:utilsLibrary,代码行数:27,代码来源:SpeakerUtils.java

示例4: onCreate

import android.media.AudioManager; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View btn = findViewById(R.id.start_alarm);
    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            StartAlarm();
        }
    });
    btn.setBackgroundResource(R.drawable.animation);
    anim = (AnimationDrawable) btn.getBackground();

    setup();
    loadClip();

    prefs.registerOnSharedPreferenceChangeListener(prefListener);
    AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, audioManager
            .getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0);
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:26,代码来源:Alarm.java

示例5: volumDown

import android.media.AudioManager; //导入方法依赖的package包/类
public static void volumDown(Activity activity, float distanceY, int mScreenWidth) {
    try {

    // 获取声音的管理者
    AudioManager audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
    // 获取当前音量
    int currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    // 获取最大音量
    int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    // 计算减少的音量   add < 0
    double add = 2 * maxVolume * distanceY / mScreenWidth;
    double changed = Math.max(0, currentVolume + add);
    // 设置音量
    audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, (int) changed, AudioManager.FLAG_PLAY_SOUND);
    ((PlayActivity) activity).showToast((int)(audioManager.getStreamVolume(AudioManager.STREAM_MUSIC) * 100 / maxVolume) + "%", true);
    } catch (Exception e){

    }
}
 
开发者ID:Leavessilent,项目名称:QuanMinTV,代码行数:20,代码来源:VolumController.java

示例6: onCreate

import android.media.AudioManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
	PhoneFinderConfigManager.setFindingFlag();
	Log.i(FindMeActivity.class.getName(), "FindMeActivity called!!!");
	audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
	originalVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_find_me);
	
	foundButton = (Button) findViewById(R.id.phone_found_button);
	foundButton.setOnClickListener(new FoundButtonListener());

	final PhoneFinderConfig config = getConfig();
	if (config == null) {
		finish();
		return;
	}
	
	audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, config.getVolume(), 0);
	mediaPlayer = MediaPlayer.create(this.getBaseContext(), R.raw.findme);
	mediaPlayer.setLooping(true);
	mediaPlayer.start();
	
	finisherThread = new Thread(new FinisherThread(config));
	finisherThread.start();
}
 
开发者ID:masterjc,项目名称:bluewatcher,代码行数:27,代码来源:FindMeActivity.java

示例7: volumUp

import android.media.AudioManager; //导入方法依赖的package包/类
public static void volumUp(Activity activity, float distanceY, int mScreenWidth) {
    try {

        // 获取声音的管理者
        AudioManager audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
        // 获取当前音量
        int currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        // 获取最大音量
        int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        // 计算增加的音量   add < 0
        double add = 2 * maxVolume * distanceY / mScreenWidth;
        double changed = Math.min(maxVolume, currentVolume + add);
        // 设置音量
        audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, (int) changed, AudioManager.FLAG_PLAY_SOUND);
        ((PlayActivity) activity).showToast((int)(audioManager.getStreamVolume(AudioManager.STREAM_MUSIC) * 100 / maxVolume) + "%", true);
    }catch (Exception e){

    }
}
 
开发者ID:Leavessilent,项目名称:QuanMinTV,代码行数:20,代码来源:VolumController.java

示例8: setVolume

import android.media.AudioManager; //导入方法依赖的package包/类
private void setVolume(float param){
    AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    int f;
    if(param < 4){
        f = (int) (param / 16 / 2 * volumeMax);
    }else {
        param-=2;
        f = (int) (param / 16  * volumeMax);
    }
    mAudioManager.setStreamVolume(STREAM_MUSIC,f,FLAG_SHOW_UI);
}
 
开发者ID:xfangfang,项目名称:NeuTV,代码行数:12,代码来源:VideoController.java

示例9: onProgressChanged

import android.media.AudioManager; //导入方法依赖的package包/类
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
    AudioManager audioManager = getAudioManager();
    if (audioManager != null) {
        audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, i, 0);
    }
    volumeDown.setImageResource(i == 0 ? R.drawable.ic_volume_off_white_24dp : R.drawable.ic_volume_down_white_24dp);
}
 
开发者ID:h4h13,项目名称:RetroMusicPlayer,代码行数:9,代码来源:VolumeFragment.java

示例10: volumeUp

import android.media.AudioManager; //导入方法依赖的package包/类
public void volumeUp() {
    AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    if (am == null)
        return;

    int currVolume = am.getStreamVolume(AudioManager.STREAM_MUSIC);
    int maxVolume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    currVolume = currVolume +(maxVolume/10);
    if (currVolume > maxVolume)
        currVolume = maxVolume;

    am.setStreamVolume(AudioManager.STREAM_MUSIC, currVolume, AudioManager.FLAG_SHOW_UI);
}
 
开发者ID:dmllr,项目名称:IdealMedia,代码行数:14,代码来源:PlayerService.java

示例11: volumeDown

import android.media.AudioManager; //导入方法依赖的package包/类
public void volumeDown() {
    AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    if (am == null)
        return;

    int currVolume = am.getStreamVolume(AudioManager.STREAM_MUSIC);
    int maxVolume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    currVolume = currVolume - (maxVolume/10);
    if (currVolume < 0)
        currVolume = 0;

    am.setStreamVolume(AudioManager.STREAM_MUSIC, currVolume, AudioManager.FLAG_SHOW_UI);
}
 
开发者ID:dmllr,项目名称:IdealMedia,代码行数:14,代码来源:PlayerService.java

示例12: onValueChanged

import android.media.AudioManager; //导入方法依赖的package包/类
@Override
public void onValueChanged(int value) {

	RangeSetting setting = (RangeSetting) mSetting;
	setting.value = value; 
	int v = (int) (100f / 15 * value); // value in % 
	
	System.out.println("New value: " + setting.value + ", value%=" + v);
	
	AudioManager manager = mManager;
	
	// get max value for state
	int maxv1 = manager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
	int maxv2 = manager.getStreamMaxVolume(AudioManager.STREAM_RING);
	int maxv3 = manager.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION);
	int maxv4 = manager.getStreamMaxVolume(AudioManager.STREAM_ALARM);

	// get current volumes
	int v1, v2, v3, v4;

	manager.setStreamVolume(AudioManager.STREAM_MUSIC, v1 =  round(maxv1 * v / 100f), AudioManager.FLAG_PLAY_SOUND);
	manager.setStreamVolume(AudioManager.STREAM_RING, v2 = round(maxv2 * v / 100f), 0);
	manager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, v3 = round(maxv3 * v / 100f), 0);
	manager.setStreamVolume(AudioManager.STREAM_ALARM, v4 = round(maxv4 * v / 100f), 0);
	
	if (manager.getRingerMode() == AudioManager.RINGER_MODE_SILENT & v2 > 0) {
		manager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
	} else if (manager.getRingerMode() != AudioManager.RINGER_MODE_SILENT && v2 == 0) {
		manager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
	}

	setting.descr = mActivity.getString(R.string.txt_master_volume_desc, v2, v3, v1, v4);
	setting.updateView();
	
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:36,代码来源:MasterVolumeSettingHandler.java

示例13: onVolumeChange

import android.media.AudioManager; //导入方法依赖的package包/类
@Override
public void onVolumeChange(float dy) {
    AudioManager am = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
    int maxVolume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    mVolume = dy * 4f / getHeight() * maxVolume + mVolume;
    mVolume = Math.min(maxVolume, Math.max(mVolume, 0));
    am.setStreamVolume(AudioManager.STREAM_MUSIC, (int) mVolume, 0);
    double volumePercent = mVolume / maxVolume;
    int progress = (int) Math.min(Math.max(0, volumePercent * 100), 100);
    if (!mVolumeProgress.isShown()) {
        mVolumeProgress.setVisibility(VISIBLE);
    }
    mVolumeProgress.setProgress(progress);
}
 
开发者ID:TedaLIEz,项目名称:ParsingPlayer,代码行数:15,代码来源:ParsingVideoView.java

示例14: preparePhoneToPlayAudio

import android.media.AudioManager; //导入方法依赖的package包/类
private void preparePhoneToPlayAudio(Context context) {
    audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    originalRingerMode = audioManager.getRingerMode();

    originalRingerMode = audioManager.getRingerMode();
    originalRingerVolume = audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION);

    if(originalRingerMode != AudioManager.RINGER_MODE_NORMAL) {
        audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    }
    audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, audioManager.getStreamMaxVolume
            (AudioManager.STREAM_NOTIFICATION), 0);
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:14,代码来源:PlayAudioPresenter.java

示例15: setVolume

import android.media.AudioManager; //导入方法依赖的package包/类
private void setVolume(int x) {
    AudioManager audio = (AudioManager) Ui.ef.getBaseContext().getSystemService(Context.AUDIO_SERVICE);
    int vol = (int) (audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC) / ((float)width - Ui.cd.getHt(80))  * (x - Ui.cd.getHt(10)));
    audio.setStreamVolume( AudioManager.STREAM_MUSIC, vol, 0);
    if(vol < 0){
        vol = 0;
    }else if(vol > audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC)){
        vol = audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    }
    text.setText(vol+"",true);

}
 
开发者ID:KishanV,项目名称:Android-Music-Player,代码行数:13,代码来源:VolumeRocker.java


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