CosyDVR icon indicating copy to clipboard operation
CosyDVR copied to clipboard

Silence ringer during recording transition

Open vilhelmgray opened this issue 8 years ago • 3 comments

MediaRecorder produces a "chime" sound on state changes (e.g. on the stop and start of recordings). Some versions of Android use STREAM_SYSTEM to produce the sound, but others such as version 4.2.1 on the Galaxy Nexus use STREAM_RING. This patch silences the ringer during recording transitions in order to prevent the "chime" sound from being heard on each RestartRecording method call on relevant Android versions.

vilhelmgray avatar Mar 13 '16 17:03 vilhelmgray

This patch should theoretically not be necessary when setStreamSolo is used, but setStreamSolo appears to work as a no-op on newer versions of Android. A more encompassing solution may be necessary to cover Android versions where MediaRecorder uses a stream other than STREAM_SYSTEM or STREAM_RING.

The setStreamVolume method should not be used on STREAM_RING since a vibration may occur on every transition if the ringer mode is set to RINGER_MODE_NORMAL.

vilhelmgray avatar Mar 13 '16 17:03 vilhelmgray

Yes. I've found that on different devices MediaRecorder uses different streams. That's why Solo+Mute method was chosen. But if you confirm that it doesn't work on newer devices and your patch fixes this issue, let me know what exact device is it and of course your patch will be merged to upstream.

sergstetsuk avatar Mar 14 '16 01:03 sergstetsuk

The setStreamSolo method appears to be a no-op (or at the very least does not isolate the audio stream) on Android version 5.0.1 running on a Samsung Galaxy S4 as well as on Android version 5.1.1 running on a Samsung Galaxy S6. I haven't tested the setStreamSolo method on a Android version 4.x.x device, so it's possible that it behaves correctly on those. Regardless, this patch should work for either version series of Android.

It's important to note that this patch is only a partial solution, fixing the issue only for those devices whose MediaRecorder uses STREAM_RING. A more complete solution would use the requestAudioFocus adjustStreamVolume + ADJUST_MUTE or ADJUST_UNMUTE approach you've mentioned previous closed pull request. However, setRingerMode may still be necessary in such case (I'm unsure of the behavior of requestAudioFocus) in order to avoid the vibration that occurs when bringing the ringer volume down to 0 when the ringer mode is set to RINGER_MODE_NORMAL as is default on most devices.

vilhelmgray avatar Mar 14 '16 02:03 vilhelmgray