Example usage for android.media AudioManager getStreamMaxVolume

List of usage examples for android.media AudioManager getStreamMaxVolume

Introduction

In this page you can find the example usage for android.media AudioManager getStreamMaxVolume.

Prototype

public int getStreamMaxVolume(int streamType) 

Source Link

Document

Returns the maximum volume index for a particular stream.

Usage

From source file:Main.java

private static void setVolume(AudioManager manager, int audioStream, int setValue) {
    int volume = manager.getStreamMaxVolume(audioStream) * setValue / 100;
    manager.setStreamVolume(audioStream, volume, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
}

From source file:Main.java

public static int getVolumeMax(Context context) {
    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    return audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL);
}

From source file:Main.java

public static void setCurrentVolume(int percent, Context mc) {
    AudioManager am = (AudioManager) mc.getSystemService(Context.AUDIO_SERVICE);
    int maxvolume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    am.setStreamVolume(AudioManager.STREAM_MUSIC, (maxvolume * percent) / 100,
            AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
    am.setMode(AudioManager.MODE_INVALID);
}

From source file:Main.java

public static int getMaxVolume(Context context) {
    AudioManager manager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    int max = manager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);

    return max;/*from   w w  w  .jav  a 2s. c om*/
}

From source file:Main.java

public static int getAlarmVolumeFromPercentage(AudioManager audioManager, int audioStream, float percentage) {
    int volume = (int) Math.ceil((double) audioManager.getStreamMaxVolume(audioStream) * (percentage / 100.0d));
    return volume;
}

From source file:Main.java

public static int getStreamMaxVolume(Context context, int streamType) {
    AudioManager audioManager = getAudioManager(context);
    if (audioManager == null)
        return 0;

    return audioManager.getStreamMaxVolume(streamType);
}

From source file:Main.java

public static int getMaxSpeakerVolume(Context context) {

    if (context == null) {
        return -1;
    }//from www. j a  v  a 2 s.  co  m

    int level = -1;
    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

    if (audioManager != null) {
        level = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    }
    return level;
}

From source file:Main.java

public static int getMaxVoice(Context context) {
    AudioManager audioManager = (AudioManager) context.getSystemService(Service.AUDIO_SERVICE);
    // return audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    return audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM);
}

From source file:capstone.se491_phm.Alarm.java

public static void loudest(Context context, int stream) {
    AudioManager manager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    int loudest = manager.getStreamMaxVolume(stream);
    manager.setStreamVolume(stream, loudest, 0);
}

From source file:nth.com.ares.utils.Utils.java

public static void playSound(Context context, int sound) {
    AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    int currentVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC);
    int maxVolume = audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    float percent = 0.7f;
    int seventyVolume = (int) (maxVolume * percent);
    audio.setStreamVolume(AudioManager.STREAM_MUSIC, seventyVolume, 0);
    final MediaPlayer mp = MediaPlayer.create(context, sound);
    mp.start();/*www  . j a  va2 s.  c  om*/
}