Closed vilhelmgray closed 8 years ago
The MediaRecorder plays notification sounds at the start (end) of record. As I said the main idea is to eliminate these annoying sounds during background operation. In different devices MediaRecorder uses different streams (STREAM_SYSTEM of STREAM_RING) for notification. So I decided to mute all the sounds. For this purpose we can use 2 step muting. First:
manager.setStreamSolo
to mute all sound streams except system. Then mute the system stream itself:
manager.setStreamMute
After recording is restarted all these streams are unmuted. Restart lasts a few seconds.
If your device behaves different you should try to use some different approach. I see that these functions are deprecated since API23. Instead it is recommended to use:
requestAudioFocus adjustStreamVolume + ADJUST_MUTE or ADJUST_UNMUTE
http://developer.android.com/reference/android/media/AudioManager.html#setStreamSolo%28int,%20boolean%29
Here is a sample for mute a stream using both versions: http://stackoverflow.com/questions/33057428/alternative-for-deprecated-audiomanger-setstreammute
After playing around with my device, I figured out what caused my confusion: I had my ringtone volume muted, so the MediaRecorder beep didn't sound for me and I falsely believed I solved the issue; this patch I submitted then is not the solution.
I'm not sure why (perhaps since the methods are deprecated) my device does not behave as the code intends: assumming my ringtone volume is not muted, I always hear the MediaRecorder beep, whether CosyDVR is in the background or not. Regardless, other sounds on my system are breifly muted during the fragment split, which is still a minor annoyance.
Since I now understand that the beep occurs when the MediaRecorder start method is called, I will investigate an alternative way to configure CosyDVR such that only the beep is muted.
I've noticed that the Camera API is deprecated in favor of the android.hardware.camera2 API. The camera2 API does not play any sounds on its own for any capture or video recording actions. Perhaps a transition to this new API may resolve the mute issue; MediaActionSound can be used to play a beep when appropriate.
You can just comment out Solo and Mute functions. Then CosyDVR won't interrupt your player. CosyDVR is intended to work with Android 4+. So camera2 API is not suitable.
When the RestartRecording function is called, all non-CosyDVR sound is muted. This patch reimplements the RestartRecording sound notification by using MediaPlayer to play the system notification sound; this allows the notification sound to play without muting all the other sound on the system.