Java Code Examples for android.media.AudioManager#STREAM_ALARM

The following examples show how to use android.media.AudioManager#STREAM_ALARM . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OppoVolumePanel.java    From Noyze with Apache License 2.0 6 votes vote down vote up
@Override protected int[] getStreamIcons(StreamControl sc) {
    if (sc.streamType == STREAM_BLUETOOTH_SCO)
        return new int[] { R.drawable.oppo_ic_audio_bt, R.drawable.oppo_ic_audio_bt_mute };
    switch (sc.streamType) {
        case AudioManager.STREAM_ALARM:
            return new int[] { R.drawable.oppo_ic_audio_alarm, R.drawable.oppo_ic_audio_alarm_mute };
        case AudioManager.STREAM_RING:
            return new int[] { R.drawable.oppo_ic_audio_ring_notif, R.drawable.oppo_ic_audio_ring_notif_mute };
        case AudioManager.STREAM_NOTIFICATION:
            return new int[] { R.drawable.oppo_ic_audio_notification, R.drawable.oppo_ic_audio_notification_mute };
        case AudioManager.STREAM_MUSIC:
            return new int[] { R.drawable.oppo_ic_audio_media, R.drawable.oppo_ic_audio_media_mute };
        case AudioManager.STREAM_VOICE_CALL:
            return new int[] { R.drawable.oppo_ic_audio_phone, R.drawable.oppo_ic_audio_phone };
        default:
            return new int[] { R.drawable.oppo_ic_audio_vol, R.drawable.oppo_ic_audio_vol_mute };
    }
}
 
Example 2
Source File: BasicMediaPlayerTestCase_SetAudioStreamTypeMethod.java    From android-openslmediaplayer with Apache License 2.0 6 votes vote down vote up
private static String streamTypeToString(int streamtype) {
    switch (streamtype) {
        case AudioManager.STREAM_ALARM:
            return "ALARM";
        case AudioManager.STREAM_DTMF:
            return "DTMF";
        case AudioManager.STREAM_MUSIC:
            return "MUSIC";
        case AudioManager.STREAM_NOTIFICATION:
            return "NOTIFICATION";
        case AudioManager.STREAM_RING:
            return "RING";
        case AudioManager.STREAM_SYSTEM:
            return "SYSTEM";
        case AudioManager.STREAM_VOICE_CALL:
            return "VOICE_CALL";
        default:
            return "Unknown stream type; " + streamtype;
    }
}
 
Example 3
Source File: CalibrationLinearityActivity.java    From NoiseCapture with GNU General Public License v3.0 6 votes vote down vote up
private int getAudioOutput() {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    String value = sharedPref.getString("settings_calibration_audio_output", "STREAM_MUSIC");

    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 {
        return AudioManager.STREAM_RING;
    }
}
 
Example 4
Source File: CalibrationService.java    From NoiseCapture with GNU General Public License v3.0 6 votes vote down vote up
private int getAudioOutput() {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    String value = sharedPref.getString("settings_calibration_audio_output", "STREAM_MUSIC");

    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 {
        return AudioManager.STREAM_RING;
    }
}
 
Example 5
Source File: OpenFitService.java    From OpenFit with MIT License 6 votes vote down vote up
public void run() {
    long timeStart = Calendar.getInstance().getTimeInMillis();
    Log.d(LOG_TAG, "FindSound Start: "+timeStart);
    ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_ALARM, ToneGenerator.MAX_VOLUME);

    while(isFinding) {
        try {
            long timeDiff =  Calendar.getInstance().getTimeInMillis() - timeStart;
            Log.d(LOG_TAG, "Sound time: " + timeDiff/1000);

            toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 200); // 200 ms tone
            Thread.sleep(600L);
        }
        catch(InterruptedException ie) {
            Thread.currentThread().interrupt();
            return;
        }
    }
}
 
Example 6
Source File: OppoVolumePanel.java    From Noyze with Apache License 2.0 6 votes vote down vote up
@Override protected int[] getStreamIcons(StreamControl sc) {
    if (sc.streamType == STREAM_BLUETOOTH_SCO)
        return new int[] { R.drawable.oppo_ic_audio_bt, R.drawable.oppo_ic_audio_bt_mute };
    switch (sc.streamType) {
        case AudioManager.STREAM_ALARM:
            return new int[] { R.drawable.oppo_ic_audio_alarm, R.drawable.oppo_ic_audio_alarm_mute };
        case AudioManager.STREAM_RING:
            return new int[] { R.drawable.oppo_ic_audio_ring_notif, R.drawable.oppo_ic_audio_ring_notif_mute };
        case AudioManager.STREAM_NOTIFICATION:
            return new int[] { R.drawable.oppo_ic_audio_notification, R.drawable.oppo_ic_audio_notification_mute };
        case AudioManager.STREAM_MUSIC:
            return new int[] { R.drawable.oppo_ic_audio_media, R.drawable.oppo_ic_audio_media_mute };
        case AudioManager.STREAM_VOICE_CALL:
            return new int[] { R.drawable.oppo_ic_audio_phone, R.drawable.oppo_ic_audio_phone };
        default:
            return new int[] { R.drawable.oppo_ic_audio_vol, R.drawable.oppo_ic_audio_vol_mute };
    }
}
 
Example 7
Source File: WebRtcAudioUtils.java    From webrtc_android with MIT License 6 votes vote down vote up
private static void logAudioStateVolume(String tag, AudioManager audioManager) {
  final int[] streams = {
      AudioManager.STREAM_VOICE_CALL,
      AudioManager.STREAM_MUSIC,
      AudioManager.STREAM_RING,
      AudioManager.STREAM_ALARM,
      AudioManager.STREAM_NOTIFICATION,
      AudioManager.STREAM_SYSTEM
  };
  Logging.d(tag, "Audio State: ");
  // Some devices may not have volume controls and might use a fixed volume.
  boolean fixedVolume = isVolumeFixed(audioManager);
  Logging.d(tag, "  fixed volume=" + fixedVolume);
  if (!fixedVolume) {
    for (int stream : streams) {
      StringBuilder info = new StringBuilder();
      info.append("  " + streamTypeToString(stream) + ": ");
      info.append("volume=").append(audioManager.getStreamVolume(stream));
      info.append(", max=").append(audioManager.getStreamMaxVolume(stream));
      logIsStreamMute(tag, audioManager, stream, info);
      Logging.d(tag, info.toString());
    }
  }
}
 
Example 8
Source File: GroupedMenuItemForVolumeAction.java    From talkback with Apache License 2.0 6 votes vote down vote up
@Override
public String getText() {
  switch (volumeStreamType) {
    case AudioManager.STREAM_MUSIC:
      return context.getString(R.string.volume_menu_media);
    case AudioManager.STREAM_VOICE_CALL:
      return context.getString(R.string.volume_menu_call);
    case AudioManager.STREAM_RING:
      return context.getString(R.string.volume_menu_ring);
    case AudioManager.STREAM_ALARM:
      return context.getString(R.string.volume_menu_alarm);
    case AudioManager.STREAM_ACCESSIBILITY:
      return context.getString(R.string.volume_menu_accessibility);
  }
  return "";
}
 
Example 9
Source File: GroupedMenuItemForVolumeAction.java    From talkback with Apache License 2.0 6 votes vote down vote up
@Override
public int getIconResource() {
  switch (volumeStreamType) {
    case AudioManager.STREAM_MUSIC:
      return R.drawable.quantum_ic_music_note_white_24;
    case AudioManager.STREAM_VOICE_CALL:
      return R.drawable.quantum_ic_phone_white_24;
    case AudioManager.STREAM_RING:
      return R.drawable.quantum_ic_vibration_white_24;
    case AudioManager.STREAM_ALARM:
      return R.drawable.quantum_ic_alarm_white_24;
    case AudioManager.STREAM_ACCESSIBILITY:
      return R.drawable.quantum_ic_accessibility_new_white_24;
  }
  return 0;
}
 
Example 10
Source File: WebRtcAudioUtils.java    From webrtc_android with MIT License 6 votes vote down vote up
private static String streamTypeToString(int stream) {
  switch (stream) {
    case AudioManager.STREAM_VOICE_CALL:
      return "STREAM_VOICE_CALL";
    case AudioManager.STREAM_MUSIC:
      return "STREAM_MUSIC";
    case AudioManager.STREAM_RING:
      return "STREAM_RING";
    case AudioManager.STREAM_ALARM:
      return "STREAM_ALARM";
    case AudioManager.STREAM_NOTIFICATION:
      return "STREAM_NOTIFICATION";
    case AudioManager.STREAM_SYSTEM:
      return "STREAM_SYSTEM";
    default:
      return "STREAM_INVALID";
  }
}
 
Example 11
Source File: WebRtcAudioUtils.java    From webrtc_android with MIT License 6 votes vote down vote up
private static void logAudioStateVolume(String tag, AudioManager audioManager) {
  final int[] streams = {AudioManager.STREAM_VOICE_CALL, AudioManager.STREAM_MUSIC,
      AudioManager.STREAM_RING, AudioManager.STREAM_ALARM, AudioManager.STREAM_NOTIFICATION,
      AudioManager.STREAM_SYSTEM};
  Logging.d(tag, "Audio State: ");
  // Some devices may not have volume controls and might use a fixed volume.
  boolean fixedVolume = isVolumeFixed(audioManager);
  Logging.d(tag, "  fixed volume=" + fixedVolume);
  if (!fixedVolume) {
    for (int stream : streams) {
      StringBuilder info = new StringBuilder();
      info.append("  " + streamTypeToString(stream) + ": ");
      info.append("volume=").append(audioManager.getStreamVolume(stream));
      info.append(", max=").append(audioManager.getStreamMaxVolume(stream));
      logIsStreamMute(tag, audioManager, stream, info);
      Logging.d(tag, info.toString());
    }
  }
}
 
Example 12
Source File: WebRtcAudioUtils.java    From webrtc_android with MIT License 6 votes vote down vote up
private static String streamTypeToString(int stream) {
  switch(stream) {
    case AudioManager.STREAM_VOICE_CALL:
      return "STREAM_VOICE_CALL";
    case AudioManager.STREAM_MUSIC:
      return "STREAM_MUSIC";
    case AudioManager.STREAM_RING:
      return "STREAM_RING";
    case AudioManager.STREAM_ALARM:
      return "STREAM_ALARM";
    case AudioManager.STREAM_NOTIFICATION:
      return "STREAM_NOTIFICATION";
    case AudioManager.STREAM_SYSTEM:
      return "STREAM_SYSTEM";
    default:
      return "STREAM_INVALID";
  }
}
 
Example 13
Source File: MyPlayer.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
private int getStreamType() {
    switch (volume) {
        case Alarm.VOLUME_MODE_ALARM:
            return AudioManager.STREAM_ALARM;
        case Alarm.VOLUME_MODE_RINGTONE:
            return AudioManager.STREAM_RING;
        case Alarm.VOLUME_MODE_NOTIFICATION:
            return AudioManager.STREAM_NOTIFICATION;
        case Alarm.VOLUME_MODE_MEDIA:
        default:
            return AudioManager.STREAM_MUSIC;
    }
}
 
Example 14
Source File: GroupedMenuItemForVolumeAction.java    From talkback with Apache License 2.0 5 votes vote down vote up
private boolean canStreamBeMuted() {
  // TODO: Instead of hiding the mute button for alarm and accessibility, investigate
  // a more elegant way of determining is a volume stream can be muted and/or manually setting
  // the volume to 0 instead of using ADJUST_STREAM_MUTE. There's a bug in AudioManager that
  // causes some volume types on certain versions to not be muteable. Alarm and accessibility
  // volume are generally not considered "muteable" volume types, so manually hiding the mute
  // button for these streams doesn't significantly impact user experience.
  boolean isValidStreamType =
      (volumeStreamType != AudioManager.STREAM_ALARM)
          && (volumeStreamType != AudioManager.STREAM_ACCESSIBILITY);
  return isValidStreamType
      && ((audioManager != null) && (audioManager.getStreamMinVolume(volumeStreamType) == 0));
}
 
Example 15
Source File: MyPlayer.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
private int getStreamType() {
    switch (volume) {
        case Alarm.VOLUME_MODE_ALARM:
            return AudioManager.STREAM_ALARM;
        case Alarm.VOLUME_MODE_RINGTONE:
            return AudioManager.STREAM_RING;
        case Alarm.VOLUME_MODE_NOTIFICATION:
            return AudioManager.STREAM_NOTIFICATION;
        case Alarm.VOLUME_MODE_MEDIA:
        default:
            return AudioManager.STREAM_MUSIC;
    }
}
 
Example 16
Source File: AlarmNotifications.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
private static void startAlert(Context context, @NonNull Uri soundUri, final boolean isAlarm) throws IOException
{
    final long fadeInMillis = (isAlarm ? AlarmSettings.loadPrefAlarmFadeIn(context) : 0);
    final int streamType = (isAlarm ? AudioManager.STREAM_ALARM : AudioManager.STREAM_NOTIFICATION);
    player.setAudioStreamType(streamType);

    try {
        player.setDataSource(context, soundUri);
        player.setOnPreparedListener(new MediaPlayer.OnPreparedListener()
        {
            @Override
            public void onPrepared(MediaPlayer mediaPlayer)
            {
                mediaPlayer.setLooping(isAlarm);
                if (Build.VERSION.SDK_INT >= 16) {
                    mediaPlayer.setNextMediaPlayer(null);
                }
                if (audioManager != null) {
                    audioManager.requestAudioFocus(null, streamType, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
                }

                if (fadeInMillis > 0) {
                    startFadeIn(fadeInMillis);
                } else player.setVolume(1, 1);

                mediaPlayer.start();
            }
        });
        player.prepareAsync();

    } catch (IOException e) {
        Log.e(TAG, "startAlert: failed to setDataSource! " + soundUri.toString());
        throw e;
    }
}
 
Example 17
Source File: MediaControllerCompatApi21.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
private static int toLegacyStreamType(AudioAttributes aa) {
    // flags to stream type mapping
    if ((aa.getFlags() & AudioAttributes.FLAG_AUDIBILITY_ENFORCED)
            == AudioAttributes.FLAG_AUDIBILITY_ENFORCED) {
        return STREAM_SYSTEM_ENFORCED;
    }
    if ((aa.getFlags() & FLAG_SCO) == FLAG_SCO) {
        return STREAM_BLUETOOTH_SCO;
    }

    // usage to stream type mapping
    switch (aa.getUsage()) {
        case AudioAttributes.USAGE_MEDIA:
        case AudioAttributes.USAGE_GAME:
        case AudioAttributes.USAGE_ASSISTANCE_ACCESSIBILITY:
        case AudioAttributes.USAGE_ASSISTANCE_NAVIGATION_GUIDANCE:
            return AudioManager.STREAM_MUSIC;
        case AudioAttributes.USAGE_ASSISTANCE_SONIFICATION:
            return AudioManager.STREAM_SYSTEM;
        case AudioAttributes.USAGE_VOICE_COMMUNICATION:
            return AudioManager.STREAM_VOICE_CALL;
        case AudioAttributes.USAGE_VOICE_COMMUNICATION_SIGNALLING:
            return AudioManager.STREAM_DTMF;
        case AudioAttributes.USAGE_ALARM:
            return AudioManager.STREAM_ALARM;
        case AudioAttributes.USAGE_NOTIFICATION_RINGTONE:
            return AudioManager.STREAM_RING;
        case AudioAttributes.USAGE_NOTIFICATION:
        case AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_REQUEST:
        case AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT:
        case AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_DELAYED:
        case AudioAttributes.USAGE_NOTIFICATION_EVENT:
            return AudioManager.STREAM_NOTIFICATION;
        case AudioAttributes.USAGE_UNKNOWN:
        default:
            return AudioManager.STREAM_MUSIC;
    }
}
 
Example 18
Source File: AlertPlayer.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
public static int getAlertPlayerStreamType() {
    return AudioManager.STREAM_ALARM;
}
 
Example 19
Source File: AlertPlayer.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public static int getAlertPlayerStreamType() {
    return AudioManager.STREAM_ALARM;
}
 
Example 20
Source File: SeekBarVolumizer.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private static boolean isAlarmsStream(int stream) {
    return stream == AudioManager.STREAM_ALARM;
}