Example usage for android.media AudioManager STREAM_ALARM

List of usage examples for android.media AudioManager STREAM_ALARM

Introduction

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

Prototype

int STREAM_ALARM

To view the source code for android.media AudioManager STREAM_ALARM.

Click Source Link

Document

Used to identify the volume of audio streams for alarms

Usage

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:Main.java

public static void setVoice(Context context, int voice) {
    AudioManager audioManager = (AudioManager) context.getSystemService(Service.AUDIO_SERVICE);

    // audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, voice, 0);
    audioManager.setStreamVolume(AudioManager.STREAM_ALARM, voice, 0);
}

From source file:Main.java

public static void setAudioManage(Context context) {
    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    audioManager.setStreamMute(AudioManager.STREAM_SYSTEM, true);
    audioManager.setStreamMute(AudioManager.STREAM_MUSIC, true);
    audioManager.setStreamVolume(AudioManager.STREAM_ALARM, 0, 0);
    audioManager.setStreamVolume(AudioManager.STREAM_DTMF, 0, 0);
    audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 0, 0);
    audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0);
}

From source file:Main.java

public static void silentAlarm(Context context) {
    if (player != null) {
        Log.i("AlarmHelper", "silented");
        try {/*from w  ww  .j ava  2 s.  c  o m*/
            if (player.isLooping()) {
                player.setLooping(false);
            }
            player.pause();
            player.stop();
            player.release();
        } catch (IllegalStateException e) {
            AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
            am.setStreamVolume(AudioManager.STREAM_ALARM, 0, 0);
        }

        // player.setVolume(0, 0);
        AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        am.setStreamVolume(AudioManager.STREAM_ALARM, mUserVolume, 0);
    } else {
        Log.i("AlarmHelper", "ring zero");
        AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        am.setStreamVolume(AudioManager.STREAM_ALARM, 0, 0);
    }

    if (vibrator != null) {
        vibrator.cancel();
    } else {
        vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
        vibrator.cancel();
    }
}

From source file:Main.java

/**
 * Play an alarm sound on the device//from  www  .  j av  a 2 s .c om
 *
 * @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:capstone.se491_phm.Alarm.java

@SuppressWarnings("deprecation")
public static void siren(Context context) {
    if (null == pool) {
        pool = new SoundPool(5, AudioManager.STREAM_ALARM, 0);
    }//from  www.  j a  va2s  . c o m
    if (-1 == id) {
        id = pool.load(context.getApplicationContext(), R.raw.alarm, 1);
        loudest(context, AudioManager.STREAM_ALARM);
        pool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
            @Override
            public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
                soundPool.play(id, 1.0f, 1.0f, 1, 3, 1.0f);
            }
        });
        loudest(context, AudioManager.STREAM_ALARM);
        pool.play(id, 1.0f, 1.0f, 1, 3, 1.0f);
    } else {
        loudest(context, AudioManager.STREAM_ALARM);
        pool.play(id, 1.0f, 1.0f, 1, 3, 1.0f);
    }
}

From source file:com.vrjco.v.demo.MainActivity.java

private void initialize_Layout() {
    tvlat = (TextView) findViewById(R.id.tv_lat);
    tvlongi = (TextView) findViewById(R.id.tv_longi);
    tvtestlat = (TextView) findViewById(R.id.test_lat);
    tvtestlongi = (TextView) findViewById(R.id.test_longi);
    tvSameLocation = (TextView) findViewById(R.id.check_loc);
    bStart = (Button) findViewById(R.id.bstart);
    bTest = (Button) findViewById(R.id.btest);
    test_is_set = false;/*from w w w.j  a v  a  2  s .co m*/
    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    logLocationListener = new LogLocationListener();
    testLocationListener = new TestLocationListener();
    handler = new Handler(getMainLooper());
    //noinspection deprecation
    sp = new SoundPool(1, AudioManager.STREAM_ALARM, 0);
    beep_sound = sp.load(getApplicationContext(), R.raw.beep, 1);
}

From source file:nodomain.freeyourgadget.gadgetbridge.activities.FindPhoneActivity.java

public void playRingtone() {
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    if (mAudioManager != null) {
        userVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM);
    }//  w  w w  .  j a v a  2  s.com
    mp = new MediaPlayer();

    Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);

    try {
        mp.setDataSource(this, ringtoneUri);
        mp.setAudioStreamType(AudioManager.STREAM_ALARM);
        mp.setLooping(true);
        mp.prepare();
        mp.start();
    } catch (IOException ignore) {
    }
    mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM,
            mAudioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM), AudioManager.FLAG_PLAY_SOUND);

}

From source file:com.metinkale.prayerapp.vakit.AlarmReceiver.java

public static int getStreamType(Context c) {
    String ezanvolume = PreferenceManager.getDefaultSharedPreferences(c).getString("ezanvolume", "noti");
    switch (ezanvolume) {
    case "alarm":
        return AudioManager.STREAM_ALARM;
    case "media":
        return AudioManager.STREAM_MUSIC;
    default:/*from   ww  w .  j  av  a  2 s .com*/
        return AudioManager.STREAM_RING;

    }
}

From source file:com.renard.ocr.documents.viewing.single.DocumentActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setVolumeControlStream(AudioManager.STREAM_ALARM);
    supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_document);
    if (!init(savedInstanceState)) {
        finish();//from w w w . j  av a  2 s . c o m
        return;
    }

    if (savedInstanceState == null && isStartedAfterAScan(getIntent())) {
        showResultDialog();
    } else {
        mAnalytics.sendScreenView("Document");
    }
    setDocumentFragmentType();
    initToolbar();
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    mActionCallback = new TtsActionCallback(this);
}