How do I play a sound simultaneously with the camera shutter going off?
In my application, I have an inset camera preview. It takes 3 pictures automatically after 5 seconds of the activity starting. During this time the application is receiving a range of values via Bluetooth. Everytime the values are greater than a preset threshold, the application plays a tone, which is done using MediaPlayer.
The problem is that when the camera goes off, the shutter click sound seems to take over all the audio, and the tone being played stops and only resumes after the 3 shutter clicks. I don’t want to silence the camera shutter, so is there a way I can get the tone to play with shutter clicks? This is all happening in one activity.
Thanks
One possible solution would be to use the hidden
ENFORCED_AUDIBLEstream type for your tones. This is the stream type that the camera shutter sound most likely will use, so it won’t be muted unless the shutter sound has been muted.Note that this stream type wasn’t introduced until ICS (or maybe it was GB/HC, I can’t say for sure off the top of my head), so it won’t be compatible with every version of Android in existence. The integer value for this stream type identifier is 7, but if you want to check if exists / get its value programmatically you might be able to do so using reflection on the
AudioSystemclass.Here’s an example of how this could be done:
Keep in mind that if you use this stream type you’ll always get your tones in the loudspeaker even if the user has e.g. a 3.5mm wired headset attached, and even if the user has put his/her phone in silent mode.