Is there any way to replace the camera shutter sound in Android? I'd like to replace the shutter sound, the sound the camera makes when snapping a photo, with something else in code.
I used this code to silence the phone right before taking the picture, and unsilencing it right after:
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true);
I'd prefer to replace the sound with another .mp3
or .ogg
that can be set dynamically by the user.
I understand if you have a rooted phone, you can replace the file. This is not a solution for my app.
The sound is played from the cameraservice in the native layer of any device (libcameraservice.so). And hence any modifications in the played out sound has to be done here.
On hindsight:
The sound playing part in the above library is a result of a shutter callback from device camera. This checks for the volume index and hence does not playout any sound when you set the device to mute. When the event is later transferred to the app layer your implementation of Camera.ShutterCallback (refer to http://developer.android.com/reference/android/hardware/Camera.html#takePicture(android.hardware.Camera.ShutterCallback, android.hardware.Camera.PictureCallback, android.hardware.Camera.PictureCallback, android.hardware.Camera.PictureCallback) is called and hence here can unmute the audio manager and playback your audio file using the Android audio playback class like audio track.