Need to shut off the sound MediaRecorder plays when the state changes
Asked Answered
S

1

2

I have tried the changes found at the link below but with no avail.

How to shut off the sound MediaRecorder plays when the state changes

I tried both

AudioManager audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamMute(AudioManager.STREAM_SYSTEM, false);
audioManager.setStreamMute(AudioManager.STREAM_MUSIC,false);

and

// disable sound for recording.   
// disable sound when recording.
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_ALARM,true);
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_DTMF,true);
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_MUSIC,true);
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_RING,true);
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_SYSTEM,true);
((AudioManager)activity.getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_VOICE_CALL,true);

But I still get the sound when I start the media recorder. I have tried putting this code both at the start of the app and directly before the:

mediaRecorder.start();

Are there any other suggestions?

Schweiz answered 16/1, 2013 at 22:59 Comment(2)
So you are playing music and what to stop it when you do a record?Transude
No, I am recording a series of videos in sequence and saving them to a file so that I can down load the entire video in sections. The MediaRecorder play a shutter sound at the start of each video. I am trying to shut that off so it doesn't keep sounding over and over during the sequence.Schweiz
T
2

SetStreamMute works only for SYSTEM and MUSIC. For all the other you should use SetStreamVolume.

Try the following code:

AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

    audioManager.setStreamMute(AudioManager.STREAM_SYSTEM, true);
    audioManager.setStreamMute(AudioManager.STREAM_MUSIC,true);
    audioManager.setStreamVolume(AudioManager.STREAM_ALARM, 0, 0);
    audioManager.setStreamVolume(AudioManager.STREAM_DTMF, 0, 0);
    audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 0, 0);
    audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0);

For sanity check:

Log.d(TAG, String.format("%d,  %d, %d, %d, %d, %d, %d",
            audioManager.getStreamVolume(AudioManager.STREAM_SYSTEM),
            audioManager.getStreamVolume(AudioManager.STREAM_MUSIC),
            audioManager.getStreamVolume(AudioManager.STREAM_ALARM),
            audioManager.getStreamVolume(AudioManager.STREAM_DTMF),
            audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION),
            audioManager.getStreamVolume(AudioManager.STREAM_RING)
            ));

The result should give: 0, 0, 0, 0, 0, 0

Keep in mind that the games with volume (exclude setStreamMute) won't reset the previous values after activity dies, so you probably want to store them to restore in onDestroy() or earlier.

Treadwell answered 17/12, 2013 at 20:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.