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


Java AudioManager.getStreamMaxVolume方法代码示例

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


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

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

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

import android.media.AudioManager; //导入方法依赖的package包/类
public void play(int sound) {
	AudioManager mgr = (AudioManager) context
			.getSystemService(Context.AUDIO_SERVICE);
	float streamVolumeCurrent = mgr
			.getStreamVolume(AudioManager.STREAM_RING);
	float streamVolumeMax = mgr
			.getStreamMaxVolume(AudioManager.STREAM_RING);
	float volume = streamVolumeCurrent / streamVolumeMax;

	sounds.play(soundsMap.get(sound), volume, volume, 1, 0, 1.f);
}
 
开发者ID:StringMon,项目名称:homescreenarcade,代码行数:12,代码来源:SoundEngine.java

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

示例5: loadConfiguration

import android.media.AudioManager; //导入方法依赖的package包/类
private void loadConfiguration() throws JSONException {
	AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
	int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
	PhoneFinderConfig config = PhoneFinderConfigManager.load(maxVolume / 2);
	phoneFinderEnabled.setChecked(config.isAppEnabled());
	finderDelay.setEnabled(config.isAppEnabled());
	finderDelay.setText(Integer.toString(config.getDelayTime()));
	volumeBar.setMax(maxVolume);
	volumeBar.setEnabled(config.isAppEnabled());
	volumeBar.setProgress(config.getVolume().intValue());
}
 
开发者ID:masterjc,项目名称:bluewatcher,代码行数:12,代码来源:PhoneFinderConfigActivity.java

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

示例7: playSound

import android.media.AudioManager; //导入方法依赖的package包/类
/**
 * Play a preloaded sound with the soundpool
 *
 * @param soundId of the sound to play
 * @see <a href="http://www.edumobile.org/android/sound-pool-example-in-android-development/">Reference</a>
 */
private void playSound(int soundId) {
    AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
    float actualVolume = (float) audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    float maxVolume = (float) audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    float volume = actualVolume / maxVolume;

    soundPool.play(soundId, volume, volume, 1, 0, 1f);
}
 
开发者ID:AythaE,项目名称:ESDLA-Quiz,代码行数:15,代码来源:GameActivity.java

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

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

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

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

示例12: setVolume

import android.media.AudioManager; //导入方法依赖的package包/类
public static void setVolume(Context c, int value) {
    AudioManager audioManager = (AudioManager) c.getSystemService(Context.AUDIO_SERVICE);
    int maxValue = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    float val = (float) (value / 100.0 * maxValue);

    audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, Math.round(val),
            AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:9,代码来源:AndroidUtils.java

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

示例14: initVolume

import android.media.AudioManager; //导入方法依赖的package包/类
/**
 * 初始化系统音量
 */
private void initVolume(Context context) {
    audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    // 系统音量范围 [0, 15]
    maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    int currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    Log.i(TAG, "initVolume: " + "maxVolume = " + maxVolume + ", currentVolume = " + currentVolume);

    // 设置音量进度
    int curVolumePer = (int) (100.0F / maxVolume * currentVolume);
    mGestureView.setVolumeProgress(curVolumePer);
}
 
开发者ID:SethWen,项目名称:GestureVideoView,代码行数:15,代码来源:GestureVideoView.java

示例15: initAudioManager

import android.media.AudioManager; //导入方法依赖的package包/类
private void initAudioManager(Context context) {
    audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    mMaxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    // Request audio focus for playback
    int result = audioManager.requestAudioFocus(afChangeListener,
            // Use the music stream.
            AudioManager.STREAM_MUSIC,
            // Request permanent focus.
            AudioManager.AUDIOFOCUS_GAIN);

    if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        // Start playback.
        abandonAudioManagerFocus();
    }
}
 
开发者ID:jiajunhui,项目名称:PlayerBase,代码行数:16,代码来源:DefaultPlayerGestureOperationCover.java


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