Java Code Examples for android.media.AudioManager#STREAM_RING

The following examples show how to use android.media.AudioManager#STREAM_RING . 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: 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 2
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 3
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 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: VolumeMonitor.java    From talkback with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the volume announcement text for the specified stream.
 *
 * @param streamType The stream to announce.
 * @return The volume announcement text for the stream.
 */
private String getAnnouncementForStreamType(int templateResId, int streamType) {
  // The ringer has special cases for silent and vibrate.
  if (streamType == AudioManager.STREAM_RING) {
    switch (audioManager.getRingerMode()) {
      case AudioManager.RINGER_MODE_VIBRATE:
        return context.getString(R.string.value_ringer_vibrate);
      case AudioManager.RINGER_MODE_SILENT:
        return context.getString(R.string.value_ringer_silent);
      default: // fall out
    }
  }

  final String streamName = getStreamName(streamType);
  final int volume = getStreamVolume(streamType);

  return context.getString(templateResId, streamName, volume);
}
 
Example 6
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 7
Source File: StatusBarPlusVolumePanel.java    From Noyze with Apache License 2.0 6 votes vote down vote up
@Override
public void onRingerModeChange(int ringerMode) {
    super.onRingerModeChange(ringerMode);
    if (null != mLastVolumeChange) {
        switch (mLastVolumeChange.mStreamType) {
            case AudioManager.STREAM_NOTIFICATION:
            case AudioManager.STREAM_RING:
                switch (ringerMode) {
                    case RINGER_MODE_VIBRATE:
                        icon.setImageResource(getVibrateIcon());
                        break;
                    case RINGER_MODE_SILENT:
                    default:
                        icon.setImageResource(getSilentIcon());
                        break;
                }
                break;
        }
    }
}
 
Example 8
Source File: MediaManager.java    From CSipSimple with GNU General Public License v3.0 6 votes vote down vote up
public void adjustStreamVolume(int streamType, int direction, int flags) {
	broadcastVolumeWillBeUpdated(streamType, EXTRA_VALUE_UNKNOWN);
       audioManager.adjustStreamVolume(streamType, direction, flags);
       if(streamType == AudioManager.STREAM_RING) {
       	// Update ringer 
       	ringer.updateRingerMode();
       }
       
       int inCallStream = Compatibility.getInCallStream(userWantBluetooth);
       if(streamType == inCallStream) {
       	int maxLevel = audioManager.getStreamMaxVolume(inCallStream);
       	float modifiedLevel = (audioManager.getStreamVolume(inCallStream)/(float) maxLevel)*10.0f;
       	// Update default stream level
           service.getPrefs().setPreferenceFloatValue(SipConfigManager.SND_STREAM_LEVEL, modifiedLevel);
       	
       }
}
 
Example 9
Source File: VolumePreference.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
private void initSeekBar(SeekBar seekBar, Uri defaultUri) {
    seekBar.setMax(mAudioManager.getStreamMaxVolume(mStreamType));
    mOriginalStreamVolume = mAudioManager.getStreamVolume(mStreamType);
    seekBar.setProgress(mOriginalStreamVolume);
    seekBar.setOnSeekBarChangeListener(this);
    // TODO: removed in MM, find different approach
    mContext.getContentResolver().registerContentObserver(
            System.getUriFor("volume_ring"),
            false, mVolumeObserver);
    if (defaultUri == null) {
        if (mStreamType == AudioManager.STREAM_RING) {
            defaultUri = Settings.System.DEFAULT_RINGTONE_URI;
        } else if (mStreamType == AudioManager.STREAM_NOTIFICATION) {
            defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
        } else {
            defaultUri = Settings.System.DEFAULT_ALARM_ALERT_URI;
        }
    }
    mRingtone = RingtoneManager.getRingtone(mContext, defaultUri);
    if (mRingtone != null) {
        mRingtone.setStreamType(mStreamType);
    }
}
 
Example 10
Source File: ParanoidVolumePanel.java    From Noyze with Apache License 2.0 5 votes vote down vote up
@Override public void onRingerModeChange(int ringerMode) {

        // Pulled from VolumePanel to also have the small vibration/ feedback.
        switch (ringerMode) {
            case RINGER_MODE_VIBRATE:
                if (isEnabled()) mAudioHelper.vibrate(VIBRATE_DURATION);
                break;
        }

        LOGI(TAG, "onRingerModeChange(" + ringerMode + ')');
        if (null != mLastVolumeChange &&
                (mLastVolumeChange.mStreamType == AudioManager.STREAM_NOTIFICATION ||
                 mLastVolumeChange.mStreamType == AudioManager.STREAM_RING)) {
            StreamControl sc = mStreamControls.get(mLastVolumeChange.mStreamType);
            if (null != sc) {
                switch (ringerMode) {
                    case RINGER_MODE_VIBRATE:
                        sc.iconMuteRes = getVibrateIcon();
                        break;
                    case RINGER_MODE_SILENT:
                    default:
                        sc.iconMuteRes = getSilentIcon();
                        break;
                }
            }
        }

        if (isShowing()) updateStates();
    }
 
Example 11
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 12
Source File: ParanoidVolumePanel.java    From Noyze with Apache License 2.0 5 votes vote down vote up
private void addOtherVolumes() {
    LOGI(TAG, "addOtherVolumes()");
    boolean mVoiceCapable = mAudioHelper.isVoiceCapable();
    for (StreamResources stream : StreamResources.STREAMS) {
        // Skip the phone specific ones and the active one
        final int streamType = stream.getStreamType();
        StreamControl sc = mStreamControls.get(streamType);
        if (!stream.show() || streamType == mActiveStreamType) {
            continue;
        }
        // Skip ring volume for non-phone devices
        if (!mVoiceCapable && streamType == AudioManager.STREAM_RING) {
            continue;
        }
        // Skip notification volume if linked with ring volume
        if (streamType == AudioManager.STREAM_NOTIFICATION) {
            if (mVoiceCapable && mNotificationRingerLink) {
                continue;
            } else if (linkNotifRinger) {
                // User has asked to link notification & ringer volume.
                continue;
            }
        }

        mSliderGroup.addView(sc.group);
        updateSlider(sc);
    }
}
 
Example 13
Source File: ModRinger.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
   if (intent.getAction().equals(IncreasingRingPreference.ACTION_INCREASING_RING_CHANGED) &&
           intent.getIntExtra(IncreasingRingPreference.EXTRA_STREAM_TYPE, -1) ==
               AudioManager.STREAM_RING) {
       mRingerConfig.enabled = intent.getBooleanExtra(
               IncreasingRingPreference.EXTRA_ENABLED, false);
       mRingerConfig.minVolume = intent.getFloatExtra(
               IncreasingRingPreference.EXTRA_MIN_VOLUME, 0.1f);
       mRingerConfig.rampUpDuration = intent.getIntExtra(
               IncreasingRingPreference.EXTRA_RAMP_UP_DURATION, 10);
       if (DEBUG) log(mRingerConfig.toString());
   }
}
 
Example 14
Source File: ParanoidVolumePanel.java    From Noyze with Apache License 2.0 5 votes vote down vote up
protected int[] _getStreamIcons(StreamControl sc) {
    int[] icons = getStreamIcons(sc);
    if (sc.streamType == AudioManager.STREAM_NOTIFICATION ||
            sc.streamType == AudioManager.STREAM_RING) {
        switch (mRingerMode) {
            case AudioManager.RINGER_MODE_VIBRATE:
                icons[1] = getVibrateIcon();
                break;
            case AudioManager.RINGER_MODE_SILENT:
                icons[1] = getSilentIcon();
                break;
        }
    }
    return icons;
}
 
Example 15
Source File: AudioHelper.java    From Noyze with Apache License 2.0 5 votes vote down vote up
boolean updateRingerModeAffectedStreams(Context context) {
    int ringerModeAffectedStreams;

    // make sure settings for ringer mode are consistent with device type: non voice capable
    // devices (tablets) include media stream in silent mode whereas phones don't.
    ringerModeAffectedStreams = Settings.System.getInt(context.getContentResolver(),
            Settings.System.MODE_RINGER_STREAMS_AFFECTED,
            ((1 << AudioManager.STREAM_RING)|(1 << AudioManager.STREAM_NOTIFICATION)|
             (1 << AudioManager.STREAM_SYSTEM)));

    // ringtone, notification and system streams are always affected by ringer mode
    ringerModeAffectedStreams |= (1 << AudioManager.STREAM_RING)|
            (1 << AudioManager.STREAM_NOTIFICATION)|
            (1 << AudioManager.STREAM_SYSTEM);

    if (mVoiceCapable) {
        ringerModeAffectedStreams &= ~(1 << AudioManager.STREAM_MUSIC);
    } else {
        ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
    }

    if (ringerModeAffectedStreams != mRingerModeAffectedStreams) {
        mRingerModeAffectedStreams = ringerModeAffectedStreams;
        return true;
    }
    return false;
}
 
Example 16
Source File: ParanoidVolumePanel.java    From Noyze with Apache License 2.0 5 votes vote down vote up
protected int[] getStreamIcons(StreamControl sc) {
    if (sc.streamType == AudioManager.STREAM_NOTIFICATION ||
        sc.streamType == AudioManager.STREAM_RING) {
        switch (mRingerMode) {
            case AudioManager.RINGER_MODE_VIBRATE:
                return new int[] { sc.iconRes, getVibrateIcon() };
            case AudioManager.RINGER_MODE_SILENT:
                return new int[] { sc.iconRes, getSilentIcon() };
        }
    }
    return new int[] { sc.iconRes, sc.iconMuteRes }; // Default icons
}
 
Example 17
Source File: ParanoidVolumePanel.java    From Noyze with Apache License 2.0 5 votes vote down vote up
protected int[] _getStreamIcons(StreamControl sc) {
    int[] icons = getStreamIcons(sc);
    if (sc.streamType == AudioManager.STREAM_NOTIFICATION ||
            sc.streamType == AudioManager.STREAM_RING) {
        switch (mRingerMode) {
            case AudioManager.RINGER_MODE_VIBRATE:
                icons[1] = getVibrateIcon();
                break;
            case AudioManager.RINGER_MODE_SILENT:
                icons[1] = getSilentIcon();
                break;
        }
    }
    return icons;
}
 
Example 18
Source File: DatabaseHelper.java    From Study_Android_Demo with Apache License 2.0 4 votes vote down vote up
/**
 * Loads the default volume levels. It is actually inserting the index of
 * the volume array for each of the volume controls.
 *
 * @param db the database to insert the volume levels into
 */
private void loadVolumeLevels(SQLiteDatabase db) {
    SQLiteStatement stmt = null;
    try {
        stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
                + " VALUES(?,?);");

        loadSetting(stmt, Settings.System.VOLUME_MUSIC,
                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_MUSIC]);
        loadSetting(stmt, Settings.System.VOLUME_RING,
                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_RING]);
        loadSetting(stmt, Settings.System.VOLUME_SYSTEM,
                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_SYSTEM]);
        loadSetting(
                stmt,
                Settings.System.VOLUME_VOICE,
                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_VOICE_CALL]);
        loadSetting(stmt, Settings.System.VOLUME_ALARM,
                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_ALARM]);
        loadSetting(
                stmt,
                Settings.System.VOLUME_NOTIFICATION,
                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_NOTIFICATION]);
        loadSetting(
                stmt,
                Settings.System.VOLUME_BLUETOOTH_SCO,
                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_BLUETOOTH_SCO]);

        // By default:
        // - ringtones, notification, system and music streams are affected by ringer mode
        // on non voice capable devices (tablets)
        // - ringtones, notification and system streams are affected by ringer mode
        // on voice capable devices (phones)
        int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) |
                                        (1 << AudioManager.STREAM_NOTIFICATION) |
                                        (1 << AudioManager.STREAM_SYSTEM) |
                                        (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
        if (!mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_voice_capable)) {
            ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
        }
        loadSetting(stmt, Settings.System.MODE_RINGER_STREAMS_AFFECTED,
                ringerModeAffectedStreams);

        loadSetting(stmt, Settings.System.MUTE_STREAMS_AFFECTED,
                ((1 << AudioManager.STREAM_MUSIC) |
                 (1 << AudioManager.STREAM_RING) |
                 (1 << AudioManager.STREAM_NOTIFICATION) |
                 (1 << AudioManager.STREAM_SYSTEM)));
    } finally {
        if (stmt != null) stmt.close();
    }

    loadVibrateWhenRingingSetting(db);
}
 
Example 19
Source File: DatabaseHelper.java    From Study_Android_Demo with Apache License 2.0 4 votes vote down vote up
/**
 * Loads the default volume levels. It is actually inserting the index of
 * the volume array for each of the volume controls.
 *
 * @param db the database to insert the volume levels into
 */
private void loadVolumeLevels(SQLiteDatabase db) {
    SQLiteStatement stmt = null;
    try {
        stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
                + " VALUES(?,?);");

        loadSetting(stmt, Settings.System.VOLUME_MUSIC,
                AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_MUSIC));
        loadSetting(stmt, Settings.System.VOLUME_RING,
                AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_RING));
        loadSetting(stmt, Settings.System.VOLUME_SYSTEM,
                AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_SYSTEM));
        loadSetting(
                stmt,
                Settings.System.VOLUME_VOICE,
                AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_VOICE_CALL));
        loadSetting(stmt, Settings.System.VOLUME_ALARM,
                AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_ALARM));
        loadSetting(
                stmt,
                Settings.System.VOLUME_NOTIFICATION,
                AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_NOTIFICATION));
        loadSetting(
                stmt,
                Settings.System.VOLUME_BLUETOOTH_SCO,
                AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO));

        // By default:
        // - ringtones, notification, system and music streams are affected by ringer mode
        // on non voice capable devices (tablets)
        // - ringtones, notification and system streams are affected by ringer mode
        // on voice capable devices (phones)
        int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) |
                                        (1 << AudioManager.STREAM_NOTIFICATION) |
                                        (1 << AudioManager.STREAM_SYSTEM) |
                                        (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
        if (!mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_voice_capable)) {
            ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
        }
        loadSetting(stmt, Settings.System.MODE_RINGER_STREAMS_AFFECTED,
                ringerModeAffectedStreams);

        loadSetting(stmt, Settings.System.MUTE_STREAMS_AFFECTED,
                AudioSystem.DEFAULT_MUTE_STREAMS_AFFECTED);
    } finally {
        if (stmt != null) stmt.close();
    }

    loadVibrateWhenRingingSetting(db);
}
 
Example 20
Source File: SettingsContentObserver.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
private int volumeChangeDetect(int volumeStream, int previousVolume, boolean muted, AudioManager audioManager) {
    if (muted)
        return previousVolume;

    try {
        int currentVolume = audioManager.getStreamVolume(volumeStream);
        /*if (PPApplication.logEnabled()) {
            PPApplication.logE("SettingsContentObserver.volumeChangeDetect", "channel=" + volumeStream + " currentVolume=" + currentVolume);
            PPApplication.logE("SettingsContentObserver.volumeChangeDetect", "channel=" + volumeStream + " previousVolume=" + previousVolume);
            PPApplication.logE("SettingsContentObserver.volumeChangeDetect", "internalChange=" + RingerModeChangeReceiver.internalChange);
            if (volumeStream == AudioManager.STREAM_RING) {
                PPApplication.logE("[VOL] SettingsContentObserver.volumeChangeDetect", "currentVolume=" + currentVolume);
                PPApplication.logE("[VOL] SettingsContentObserver.volumeChangeDetect", "maxVolume=" + audioManager.getStreamMaxVolume(AudioManager.STREAM_RING));
            }
        }*/

        int delta = previousVolume - currentVolume;

        if (delta > 0) {
            if (!RingerModeChangeReceiver.internalChange) {
                if (volumeStream == AudioManager.STREAM_RING) {
                    RingerModeChangeReceiver.notUnlinkVolumes = true;
                    ActivateProfileHelper.setRingerVolume(context, currentVolume);
                    if (PhoneProfilesService.getInstance() != null)
                        PhoneProfilesService.getInstance().ringingVolume = currentVolume;
                }
                if (volumeStream == AudioManager.STREAM_NOTIFICATION) {
                    RingerModeChangeReceiver.notUnlinkVolumes = true;
                    ActivateProfileHelper.setNotificationVolume(context, currentVolume);
                    //PhoneProfilesService.notificationVolume = currentVolume;
                }
            }
        } else if (delta < 0) {
            if (!RingerModeChangeReceiver.internalChange) {
                if (volumeStream == AudioManager.STREAM_RING) {
                    RingerModeChangeReceiver.notUnlinkVolumes = true;
                    ActivateProfileHelper.setRingerVolume(context, currentVolume);
                    if (PhoneProfilesService.getInstance() != null)
                        PhoneProfilesService.getInstance().ringingVolume = currentVolume;
                }
                if (volumeStream == AudioManager.STREAM_NOTIFICATION) {
                    RingerModeChangeReceiver.notUnlinkVolumes = true;
                    ActivateProfileHelper.setNotificationVolume(context, currentVolume);
                    //PhoneProfilesService.notificationVolume = currentVolume;
                }
            }
        }
        return currentVolume;
    } catch (Exception e) {
        PPApplication.recordException(e);
        return -1;
    }
}