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


Java AudioManager.getStreamVolume方法代码示例

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


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

示例1: initVideoView

import android.media.AudioManager; //导入方法依赖的package包/类
protected void initVideoView() {
	try {
		AudioManager mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
		mVolumn = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
	} catch (UnsupportedOperationException e) {

	}
	//		mTryCount = 0;
	mVideoWidth = 0;
	mVideoHeight = 0;
	setSurfaceTextureListener(this);
	//		setFocusable(true);
	//		setFocusableInTouchMode(true);
	//		requestFocus();
	mCurrentState = STATE_IDLE;
	mTargetState = STATE_IDLE;
}
 
开发者ID:Zhaoss,项目名称:WeiXinRecordedDemo,代码行数:18,代码来源:MyVideoView.java

示例2: 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

示例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: initAudioManager

import android.media.AudioManager; //导入方法依赖的package包/类
private void initAudioManager() {
    mAudioManager = (AudioManager) mAppContext.getSystemService(Context.AUDIO_SERVICE);

    int mode = mAudioManager.getRingerMode();
    if (mode == AudioManager.RINGER_MODE_VIBRATE
            || mode == AudioManager.RINGER_MODE_SILENT) {
        // Normal mode will be audible and may vibrate according to user settings.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            NotificationManager n  = (NotificationManager) mAppContext.getSystemService(Context.NOTIFICATION_SERVICE);
            boolean isPolicyGranted = n != null && n.isNotificationPolicyAccessGranted();
            // fixme 7.0手机 如果没有这个权限 直接调用setRingerMode会报出 Not allowed to change Do Not Disturb state的异常.
            if (isPolicyGranted) {
                mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            }
        } else {
            mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        }
    }
    mAudioMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    int audioCurrentVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    if (mAudioMaxVolume != 0) {
        mCurrentVolume = (int) (((float) audioCurrentVolume / (float) mAudioMaxVolume) * 100);
    }
    PlayerLog.d(TAG, "initAudioManager mCurrentVolume is " + mCurrentVolume +
            " , mAudioMaxVolume is " + mAudioMaxVolume +
            " , audioCurrentVolume is " + audioCurrentVolume);
}
 
开发者ID:xinpianchang,项目名称:NSMPlayer-Android,代码行数:28,代码来源:VMoviePlayer.java

示例5: playSound

import android.media.AudioManager; //导入方法依赖的package包/类
private void playSound(Context context, Uri alert) {
    mMediaPlayer = new MediaPlayer();
    try {
        mMediaPlayer.setDataSource(context, alert);
        final AudioManager audioManager = (AudioManager) context
                .getSystemService(Context.AUDIO_SERVICE);
        if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
            mMediaPlayer.prepare();
            mMediaPlayer.start();
        }
    } catch (IOException e) {
        System.out.println("OOPS");
    }
}
 
开发者ID:akshah1997,项目名称:KJSCE-Hackathon,代码行数:16,代码来源:AlarmReceiver.java

示例6: prepareDialog

import android.media.AudioManager; //导入方法依赖的package包/类
public boolean prepareDialog() {

		// local cache
		final AudioManager manager = (AudioManager) mActivity.getSystemService(Activity.AUDIO_SERVICE);
		final SeekBar[] seekBars = mSeekBars;
		final TextView[] valueViews = mValueViews;
		final int[] volumes = mVolumes;
		final int length = seekBars.length;
		final int[] streamTypes = STREAM_TYPES;
		
		for (int i=0; i<length; i++) {
			
			// get value and max value
			int volume = manager.getStreamVolume(streamTypes[i]);
			int max = manager.getStreamMaxVolume(streamTypes[i]);
			
			// update values
			final TextView valueView = valueViews[i];
			valueView.setText(volume + "/" + max);
			
			// update seekbar
			SeekBar seekBar = seekBars[i];
			seekBar.setMax(max);
			seekBar.setProgress(volume);
			
			volumes[i] = volume; // store initial volume
			
			//Log.d(TAG, "prepare: index: " + i + ", value: " + volume + ", max: " + max + ", seekbar: " + seekBar);
		}
		return true;
	}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:32,代码来源:VolumeSettingHandler.java

示例7: getVolume

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

示例8: setVolume

import android.media.AudioManager; //导入方法依赖的package包/类
private void setVolume(final long volume, final boolean adjust){
    AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
    final int max = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    long vol= am.getStreamVolume(AudioManager.STREAM_MUSIC);
    if(adjust){
        vol += volume * max / 100;
    }else{
        vol = volume * max / 100;
    }
    am.setStreamVolume(AudioManager.STREAM_MUSIC, (int) vol, AudioManager.FLAG_VIBRATE);

    alexaManager.sendVolumeChangedEvent(volume, vol == 0, requestCallback);

    Log.i(TAG, "Volume set to : " + vol +"/"+max+" ("+volume+")");

    new Handler(Looper.getMainLooper()).post(new Runnable() {
        @Override
        public void run() {
            if(adjust) {
                Toast.makeText(BaseActivity.this, "Volume adjusted.", Toast.LENGTH_SHORT).show();
            }else{
                Toast.makeText(BaseActivity.this, "Volume set to: " + (volume / 10), Toast.LENGTH_SHORT).show();
            }
        }
    });

}
 
开发者ID:vaibhavs4424,项目名称:AI-Powered-Intelligent-Banking-Platform,代码行数:28,代码来源:BaseActivity.java

示例9: 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

示例10: updateRingerMode

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

		AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
		synchronized (this) {
			int ringerMode = audioManager.getRingerMode();
			// Silent : stop everything
			if (ringerMode == AudioManager.RINGER_MODE_SILENT) {
				stopRing();
				return;
			}

			// Vibrate
			int vibrateSetting = audioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
			// If not already started restart it
			if (vibratorThread == null && (vibrateSetting == AudioManager.VIBRATE_SETTING_ON || ringerMode == AudioManager.RINGER_MODE_VIBRATE)) {
				vibratorThread = new VibratorThread();
				vibratorThread.start();
			}

			// Vibrate only
			if (ringerMode == AudioManager.RINGER_MODE_VIBRATE || audioManager.getStreamVolume(AudioManager.STREAM_RING) == 0) {
				stopRinger();
				return;
			}

            //Ringer
			ringerWorker.startRinging(audioManager);
		}
	}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:30,代码来源:Ringer.java

示例11: getVolume

import android.media.AudioManager; //导入方法依赖的package包/类
/**
 * returns the current volume level
 *
 * @return the value in the range of 0-100
 */
public int getVolume() {

    AudioManager audioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
    int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    int currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    int volume = currentVolume * 100 / maxVolume;
    return volume;
}
 
开发者ID:theopenbit,项目名称:yaacc-code,代码行数:14,代码来源:UpnpClient.java

示例12: updateSettingState

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

	// get current volumes
	int v1 = manager.getStreamVolume(AudioManager.STREAM_MUSIC);
	int v2 = manager.getStreamVolume(AudioManager.STREAM_RING);
	int v3 = manager.getStreamVolume(AudioManager.STREAM_NOTIFICATION);
	int v4 = manager.getStreamVolume(AudioManager.STREAM_ALARM);
	
	// get max value for state
	int maxv1 = manager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
	int maxv2 = manager.getStreamMaxVolume(AudioManager.STREAM_RING);

	// get relative values in %
	int relv2 = Math.round(100f / maxv2 * v2);
	int relv1 = Math.round(100f / maxv1 * v1);
	
	int relv = Math.max(relv2 , relv1); // max between ring & music in %
	System.out.println("Music: " + relv1 + ", ringer: " + relv2 + ", max: " + relv);
	
	RangeSetting setting = (RangeSetting) mSetting;
	setting.value = round(15f / 100 * relv); // value 1 .. 15
	setting.descr = mActivity.getString(R.string.txt_master_volume_desc, v2, v3, v1, v4);
	setting.updateView();
	
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:28,代码来源:MasterVolumeSettingHandler.java

示例13: 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

示例14: 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

示例15: 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


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