Basically you need to know which stream you plan to capture, from what I heard AudioManager
is an error. If your idea is to close all existing streams and play only your sound, you can trick other noise-creating applications by doing the following:
AudioManager.setMode(AudioManager.MODE_IN_CALL); AudioManager.setStreamSolo(AudioManager.STREAM_VOICE_CALL, true);
then delete it later
AudioManager.setStreamSolo(AudioManager.STREAM_VOICE_CALL, false); AudioManager.setMode(AudioManager.MODE_NORMAL );
OR, you can mute the sound by changing the volume:
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audioManager.adjustVolume(AudioManager.ADJUST_LOWER, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
source share