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:uk.org.openseizuredetector.client.SdClientService.java

/**
 * beep for duration miliseconds.//from w w  w  .j  av  a 2 s . c o m
 */
private void beep(int duration) {
    ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_ALARM, 100);
    toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, duration);
    Log.v(TAG, "beep()");
}

From source file:com.brayanarias.alarmproject.activity.AlarmScreenActivity.java

@Override
protected void onDestroy() {
    Log.e(TAG, "on Destroy method");
    if (task != null) {
        task.cancel(true);/*from  w w w .ja v a  2 s .  c om*/
    }
    AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    audioManager.setStreamVolume(AudioManager.STREAM_ALARM, actualVolume, 0);
    if (mediaPlayer != null) {
        mediaPlayer.stop();
        mediaPlayer.release();
    }
    if (vibrator != null) {
        vibrator.cancel();
    }
    NotificationManager alarmNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    alarmNotificationManager.cancelAll();
    if (flag) {
        int deleteAlarm = getIntent().getIntExtra(Constant.alarmDeleteAfterKey, 0);
        int id = getIntent().getIntExtra(Constant.alarmIdKey, -1);

        if (deleteAlarm == 1) {
            DataBaseManager dataBaseManager = DataBaseManager.getInstance(getApplicationContext());
            AlarmDataBase.deleteAlarm(id, dataBaseManager);
        } else if (getIntent().getStringExtra(Constant.alarmDaysKey).equals("0000000")) {
            DataBaseManager dataBaseManager = DataBaseManager.getInstance(getApplicationContext());
            Alarm alarm = AlarmDataBase.getAlarmById(dataBaseManager, id);
            alarm.setActivated(0);
            AlarmDataBase.updateAlarm(alarm, dataBaseManager);
        }
        AlarmReceiver.setAlarms(getApplicationContext());
    }
    super.onDestroy();
}

From source file:se.erichansander.retrotimer.TimerKlaxon.java

private void play(boolean ring, boolean vibrate) {
    TinyTracelog.trace("5");

    // stop() checks to see if we are already playing.
    stop();/*from   www.  j  a va  2s .  co m*/

    if (ring) {
        TinyTracelog.trace("5.1");
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setOnErrorListener(new OnErrorListener() {
            public boolean onError(MediaPlayer mp, int what, int extra) {
                TinyTracelog.trace("5.1.e1");
                stop();
                return true;
            }
        });

        try {
            /*
             * Check if we are in a call. If we are, use the in-call alarm
             * resource at a low volume to not disrupt the call.
             */
            if (mTelephonyManager.getCallState() != TelephonyManager.CALL_STATE_IDLE) {
                TinyTracelog.trace("5.1.1");
                mMediaPlayer.setVolume(IN_CALL_VOLUME, IN_CALL_VOLUME);
                setDataSourceFromResource(getResources(), mMediaPlayer, R.raw.in_call_alarm);
            } else {
                TinyTracelog.trace("5.1.2");
                setDataSourceFromResource(getResources(), mMediaPlayer, R.raw.classic_alarm);
            }
        } catch (Exception ex) {
            // Failed to set data source. Not much we can do to save
            // the situation though...
            TinyTracelog.trace("5.1.e2");
        }

        try {
            final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
            // do not play alarms if stream volume is 0
            int volume = audioManager.getStreamVolume(AudioManager.STREAM_ALARM);
            TinyTracelog.trace("5.1.3 " + volume);
            if (volume != 0) {
                mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
                mMediaPlayer.setLooping(true);
                mMediaPlayer.prepare();
                if (mAudioFocusHelper != null) {
                    mAudioFocusHelper.requestFocus();
                }
                mMediaPlayer.start();
            }
        } catch (Exception ex) {
            // Failed to play ring tone. Not much we can do to save
            // the situation though...
            TinyTracelog.trace("5.1.e3");
        }
    }

    /* Start the vibrator after everything is ok with the media player */
    if (vibrate) {
        TinyTracelog.trace("5.2");
        mVibrator.vibrate(sVibratePattern, 0);
    } else {
        mVibrator.cancel();
    }

    mPlaying = true;
}

From source file:org.noise_planet.noisecapture.CalibrationLinearityActivity.java

private int getAudioOutput() {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    String value = sharedPref.getString("settings_calibration_audio_output", "STREAM_RING");

    if ("STREAM_VOICE_CALL".equals(value)) {
        return AudioManager.STREAM_VOICE_CALL;
    } else if ("STREAM_SYSTEM".equals(value)) {
        return AudioManager.STREAM_SYSTEM;
    } else if ("STREAM_RING".equals(value)) {
        return AudioManager.STREAM_RING;
    } else if ("STREAM_MUSIC".equals(value)) {
        return AudioManager.STREAM_MUSIC;
    } else if ("STREAM_ALARM".equals(value)) {
        return AudioManager.STREAM_ALARM;
    } else if ("STREAM_NOTIFICATION".equals(value)) {
        return AudioManager.STREAM_NOTIFICATION;
    } else if ("STREAM_DTMF".equals(value)) {
        return AudioManager.STREAM_DTMF;
    } else {//from   www  .  j a v  a 2 s.co m
        return AudioManager.STREAM_RING;
    }
}

From source file:com.android.deskclock.worldclock.CitiesActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setVolumeControlStream(AudioManager.STREAM_ALARM);

    mFactory = LayoutInflater.from(this);
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    mSortType = mPrefs.getInt(PREF_SORT, SORT_BY_NAME);
    mSelectedCitiesHeaderString = getString(R.string.selected_cities_label);
    if (savedInstanceState != null) {
        mQueryTextBuffer.append(savedInstanceState.getString(KEY_SEARCH_QUERY));
        mSearchMode = savedInstanceState.getBoolean(KEY_SEARCH_MODE);
        mPosition = savedInstanceState.getInt(KEY_LIST_POSITION);
    }//from  w w  w .  j av a  2s  . co  m
    updateLayout();
}

From source file:com.googlecode.mindbell.accessors.ContextAccessor.java

public int getAlarmMaxVolume() {
    AudioManager audioMan = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    return audioMan.getStreamMaxVolume(AudioManager.STREAM_ALARM);
}

From source file:com.luanthanhthai.android.liteworkouttimer.TimerFragment.java

/**
 * Sound beep/*  w ww .j a v  a 2 s. co  m*/
 */
public void countDownBeep(int duration) {
    if (enableSound) {
        ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_ALARM, 100);
        tg.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, duration);
    }
}

From source file:com.googlecode.mindbell.accessors.ContextAccessor.java

public int getAlarmVolume() {
    AudioManager audioMan = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    return audioMan.getStreamVolume(AudioManager.STREAM_ALARM);
}

From source file:com.googlecode.mindbell.accessors.ContextAccessor.java

public void setAlarmVolume(int volume) {
    AudioManager audioMan = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    audioMan.setStreamVolume(AudioManager.STREAM_ALARM, volume, 0);

}

From source file:com.ieeton.agency.activity.ChatActivity.java

private int initSoundPool() {
    mSoundPool = new SoundPool(5, AudioManager.STREAM_ALARM, 0);
    int loadId = mSoundPool.load(ChatActivity.this, R.raw.notificationsound, 1);
    return loadId;
}