Example usage for android.media AudioManager getStreamVolume

List of usage examples for android.media AudioManager getStreamVolume

Introduction

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

Prototype

public int getStreamVolume(int streamType) 

Source Link

Document

Returns the current volume index for a particular stream.

Usage

From source file:Main.java

/** Returns the volume for notifications. */
public static int getNotificationVolume(Context context) {
    AudioManager am = getAudioManager(context);
    return am.getStreamVolume(AudioManager.STREAM_NOTIFICATION);
}

From source file:Main.java

/** Returns the volume for the ringer. */
public static int getRingerVolume(Context context) {
    AudioManager am = getAudioManager(context);
    return am.getStreamVolume(AudioManager.STREAM_RING);
}

From source file:Main.java

public static final int audioVolume(Context ctx) {
    AudioManager audio = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
    return audio.getStreamVolume(AudioManager.STREAM_RING);
}

From source file:Main.java

public static int getVolume(Context context) {
    AudioManager manager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    return manager.getStreamVolume(AudioManager.STREAM_MUSIC);
}

From source file:Main.java

public static int getVolumn(Context context) {
    AudioManager audioManger = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    return audioManger.getStreamVolume(AudioManager.STREAM_MUSIC);
}

From source file:Main.java

public static int getVivaVolume(Context context) {
    AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    int amStreamMusicVol = am.getStreamVolume(AudioManager.STREAM_MUSIC);
    return getPreferences(context).getInt(VivaVolume, amStreamMusicVol);
}

From source file:Main.java

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

    return audioManager.getStreamVolume(streamType);
}

From source file:Main.java

/**
 * Play an alarm sound on the device//from ww w.  ja v  a  2 s.  c  o  m
 *
 * @param context The context
 * @return MediaPlayer
 */
public static MediaPlayer playAlarmSound(Context context) {
    MediaPlayer mediaPlayer = new MediaPlayer();
    try {
        mediaPlayer.setDataSource(context, getAlarmUri());
        final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
            mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
            mediaPlayer.prepare();
            mediaPlayer.start();
        }

        return mediaPlayer;
    } catch (IOException e) {
        return null;
    }
}

From source file:Main.java

public static void setCurrentRingerMode(Context context) {
    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
        currentMode = AudioManager.RINGER_MODE_NORMAL;
        currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_RING);
        Log.i("Current Mode Normal", currentVolume + "");
        Log.i("Vlaue of", currentMode + "");
    } else if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) {
        currentMode = AudioManager.RINGER_MODE_VIBRATE;
        Log.i("Current Mode Vibrate", currentVolume + "");
        Log.i("Vlaue of", currentMode + "");
    } else if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
        currentMode = AudioManager.RINGER_MODE_SILENT;
        Log.i("Current Mode Silent", currentVolume + "");
        Log.i("Vlaue of", currentMode + "");
    } else {/*  w  w  w  . ja  v  a 2  s  . co  m*/
        Log.i("Nothing ", "Matched above");
    }

}

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();// w ww. ja  va  2 s  . co m
}