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:com.google.android.car.kitchensink.volume.VolumeTestFragment.java

private static String streamToName(int stream) {
    switch (stream) {
    case AudioManager.STREAM_ALARM:
        return "Alarm";
    case AudioManager.STREAM_MUSIC:
        return "Music";
    case AudioManager.STREAM_NOTIFICATION:
        return "Notification";
    case AudioManager.STREAM_RING:
        return "Ring";
    case AudioManager.STREAM_VOICE_CALL:
        return "Call";
    case AudioManager.STREAM_SYSTEM:
        return "System";
    default:/*from  ww  w . j av  a2  s . com*/
        return "Unknown";
    }
}

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

public void stopSound() {
    mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, userVolume, AudioManager.FLAG_PLAY_SOUND);
    mp.stop();
    mp.reset();
    mp.release();
}

From source file:com.android.settings.service.AlarmService.java

public void startAlarmSound() throws java.io.IOException, IllegalArgumentException, IllegalStateException {

    Uri alertSound = SmsCallHelper.returnUserRingtone(this);

    if (mPlaying) {
        stopAlarm();//  ww w . j ava2  s .c om
    } else {
        mAlarmVolumeSetting = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM);
    }

    if (mMediaPlayer == null) {
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setOnErrorListener(new OnErrorListener() {
            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {
                mp.stop();
                mp.release();
                mMediaPlayer = null;
                return true;
            }
        });
    }

    mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM,
            mAudioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM), 0);

    mMediaPlayer.setDataSource(this, alertSound);
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);

    if (SmsCallHelper.returnUserRingtoneLoop(this)) {
        mMediaPlayer.setLooping(true);
    } else {
        mMediaPlayer.setLooping(false);
        mMediaPlayer.setOnSeekCompleteListener(stopSelf);
    }
    mMediaPlayer.prepare();
    mMediaPlayer.start();
    mPlaying = true;
}

From source file:com.android.settings.beanstalk.service.AlarmService.java

public void startAlarmSound() throws java.io.IOException, IllegalArgumentException, IllegalStateException {

    Uri alertSound = QuietHoursController.getInstance(this).returnUserRingtone();

    if (mPlaying) {
        stopAlarm();/*from   w  w  w  . jav a2s.co m*/
    } else {
        mAlarmVolumeSetting = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM);
    }

    if (mMediaPlayer == null) {
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setOnErrorListener(new OnErrorListener() {
            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {
                mp.stop();
                mp.release();
                mMediaPlayer = null;
                return true;
            }
        });
    }

    mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM,
            mAudioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM), 0);

    mMediaPlayer.setDataSource(this, alertSound);
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);

    if (QuietHoursController.getInstance(this).returnUserRingtoneLoop()) {
        mMediaPlayer.setLooping(true);
    } else {
        mMediaPlayer.setLooping(false);
        mMediaPlayer.setOnSeekCompleteListener(stopSelf);
    }
    mMediaPlayer.prepare();
    mMediaPlayer.start();
    mPlaying = true;
}

From source file:net.xisberto.work_schedule.alarm.AlarmMessageActivity.java

private void prepareSound(Context context, Uri alert) {
    mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK);
    try {/* w  ww.j a v  a2 s .  com*/
        mMediaPlayer.setDataSource(context, alert);
        final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
            mMediaPlayer.setLooping(true);
            mMediaPlayer.prepare();
        }
    } catch (IOException e) {
        System.out.println("OOPS");
    }
}

From source file:com.meiste.tempalarm.ui.Alarm.java

@Override
protected void onResume() {
    super.onResume();

    final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    // do not play alarms if stream volume is 0 (typically because ringer mode is silent).
    if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
        final Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
            public boolean onError(final MediaPlayer mp, final int what, final int extra) {
                Timber.e("Error occurred while playing audio.");
                mp.stop();/* w  w  w . j a v  a 2 s .  c o  m*/
                mp.reset();
                mp.release();
                mMediaPlayer = null;
                return true;
            }
        });
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
        try {
            mMediaPlayer.setDataSource(this, alert);
            mMediaPlayer.setLooping(true);
            mMediaPlayer.prepare();
            mMediaPlayer.start();
        } catch (final IOException e) {
            Timber.e("Failed to play alarm tone: %s", e);
        }
    }

    mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    mVibrator.vibrate(sVibratePattern, 0);

    mPlaying = true;
    mHandler.sendEmptyMessageDelayed(KILLER, ALARM_TIMEOUT);
}

From source file:com.onyx.deskclock.deskclock.worldclock.CitySelectionActivity.java

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

    setContentView(R.layout.cities_activity);

    RelativeLayout relativeLayout_back = (RelativeLayout) findViewById(R.id.back_function_layout);
    relativeLayout_back.setOnClickListener(new View.OnClickListener() {
        @Override/*  w  w w  .j ava 2s.c  o m*/
        public void onClick(View v) {
            finish();
        }
    });
    Toolbar toolbar = (Toolbar) findViewById(R.id.alarm_toolbar);
    setSupportActionBar(toolbar);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowTitleEnabled(false);
    }

    mSearchMenuItemController = new SearchMenuItemController(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String query) {
            mCitiesAdapter.filter(query);
            updateFastScrolling();
            return true;
        }
    }, savedInstanceState);
    mCitiesAdapter = new CityAdapter(this, mSearchMenuItemController);
    mActionBarMenuManager.addMenuItemController(new NavUpMenuItemController(this))
            .addMenuItemController(mSearchMenuItemController)
            .addMenuItemController(new SortOrderMenuItemController())
            .addMenuItemController(new SettingMenuItemController(this))
            .addMenuItemController(MenuItemControllerFactory.getInstance().buildMenuItemControllers(this));
    mCitiesList = (ListView) findViewById(R.id.cities_list);
    mCitiesList.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
    mCitiesList.setAdapter(mCitiesAdapter);

    updateFastScrolling();
}

From source file:org.hansel.myAlert.ReminderService.java

private void playSound() {

    mMediaPlayer = new MediaPlayer();
    try {//from  w  w w  . j  av  a  2s.c om
        mMediaPlayer.setDataSource(getApplicationContext(),
                Uri.parse(Util.getRingtone(getApplicationContext())));
        final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
            mMediaPlayer.prepare();
            mMediaPlayer.setLooping(true);
            mMediaPlayer.start();
        }
    } catch (IOException e) {
        System.out.println("Error tocando alarma");
    }
}

From source file:com.glanznig.beepme.view.MainActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    int action = event.getAction();
    int keyCode = event.getKeyCode();
    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (action == KeyEvent.ACTION_UP) {
            audioManager.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_RAISE,
                    AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND);
        }//from w w  w  . j  a  va  2 s.  c om
        return true;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (action == KeyEvent.ACTION_DOWN) {
            audioManager.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_LOWER,
                    AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND);
        }
        return true;
    default:
        return super.dispatchKeyEvent(event);
    }
}

From source file:com.android.settings.beanstalk.service.AlarmService.java

public void stopAlarm() {
    if (mPlaying) {

        if (mMediaPlayer != null) {
            mMediaPlayer.stop();/*ww  w. j av a 2s .  c o  m*/
            mMediaPlayer.release();
            mMediaPlayer = null;
            mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, mAlarmVolumeSetting, 0);
        }

        mPlaying = false;
    }
}