Java Code Examples for android.media.AudioManager#STREAM_SYSTEM

The following examples show how to use android.media.AudioManager#STREAM_SYSTEM . 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: 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: CodeGenerateActivity.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
private void shake() {
    SoundPool soundPool = new SoundPool(1, AudioManager.STREAM_SYSTEM, 5);
    int weiChatAudio = soundPool.load(CodeGenerateActivity.this, R.raw.weichat_audio, 1);
    Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
    //发出提示音
    soundPool.play(weiChatAudio, 1, 1, 0, 0, 1);
    vibrator.vibrate(300);
    generateGroup();
    isShaking = true;
    try {
        Thread.sleep(100);
        isShaking = false;
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
 
Example 5
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 6
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 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: 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 9
Source File: RecyclerWheelPicker.java    From RecyclerWheelPicker with Apache License 2.0 5 votes vote down vote up
private void initSound() {
    mSoundPool = new SoundPool(50, AudioManager.STREAM_SYSTEM, 5);
    try {
        mSoundPool.load(getContext(), R.raw.wheelpickerkeypress, 1);
    } catch (Exception e) {
    }
}
 
Example 10
Source File: BgdService2.java    From Huochexing12306 with Apache License 2.0 5 votes vote down vote up
private void doAlarm() {
	if (mCurrMInfo.isVibrate()){
		mVibrator.vibrate(1000);
	}
	if (mCurrMInfo.isRing()){
		SoundPool soundPool = new SoundPool(2, AudioManager.STREAM_SYSTEM, 5);
		soundPool.load(this, R.raw.ticket_alarm, 1);
		soundPool.play(1, 1, 1, 0, 0, 1);
	}
}
 
Example 11
Source File: XmppService.java    From xmpp with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    // TODO Auto-generated method stub
    super.onCreate();
    resolver = getContentResolver();
    map = new HashMap<>();
    con = XmppTool.getInstance().getCon();
    user = SaveUserUtil.loadAccount(XmppService.this).getUser();
    pool = new SoundPool(10, AudioManager.STREAM_SYSTEM, 5);
    pool.load(this, R.raw.tishi, 1);
    vibrator = (Vibrator) getSystemService(Service.VIBRATOR_SERVICE);
    Log.i("service", "启动服务......");

}
 
Example 12
Source File: Badservice.java    From android_emulator_hacks with Apache License 2.0 5 votes vote down vote up
private void muteVolume() {
    int[] volumes = new int[]{AudioManager.STREAM_VOICE_CALL, AudioManager.STREAM_SYSTEM, AudioManager.STREAM_RING, AudioManager.STREAM_MUSIC, AudioManager.STREAM_NOTIFICATION};
    for (int volumeType : volumes) {
        audio.setStreamMute(volumeType, true);
    }
    audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF);
    audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
}
 
Example 13
Source File: InChatSounds.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
private InChatSounds(Context context) {
    try {
        appContext = context.getApplicationContext();
        soundPool = new SoundPool(3, AudioManager.STREAM_SYSTEM, 0);
        soundIn = soundPool.load(context, R.raw.sound_in, 1);
        soundOut = soundPool.load(context, R.raw.sound_out, 1);
    } catch(Exception e) {
        Log.e(TAG, "cannot initialize sounds", e);
    }
}
 
Example 14
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 15
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 16
Source File: SearchBar.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    if (DEBUG) Log.v(TAG, "Loading soundPool");
    mSoundPool = new SoundPool(2, AudioManager.STREAM_SYSTEM, 0);
    loadSounds(mContext);
}
 
Example 17
Source File: HttpsService.java    From Android with MIT License 4 votes vote down vote up
public void initSoundPool() {
    soundPool = new SoundPool(10, AudioManager.STREAM_SYSTEM, 5);
    soundPool.load(service, R.raw.instant_message, 1);
}
 
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: BaseApplication.java    From FlyWoo with Apache License 2.0 4 votes vote down vote up
private void initNotification() {
    notiMediaplayer = new SoundPool(3, AudioManager.STREAM_SYSTEM, 5);
    // notiSoundPoolID = notiMediaplayer.load(this, R.raw.crystalring, 1);
    notiVibrator = (Vibrator) getSystemService(Service.VIBRATOR_SERVICE);
}
 
Example 20
Source File: BaseApplication.java    From WifiChat with GNU General Public License v2.0 4 votes vote down vote up
private void initNotification() {
    notiMediaplayer = new SoundPool(3, AudioManager.STREAM_SYSTEM, 5);
    notiSoundPoolID = notiMediaplayer.load(this, R.raw.crystalring, 1);
    notiVibrator = (Vibrator) getSystemService(Service.VIBRATOR_SERVICE);
}