Search code examples
javaandroidandroid-cameraandroid-sound

camera2 API shutter sound is different than built-in camera's and is inconsistent across different devices


I wrote some code to play the shuttersound for Android using the camera2 API. The code is:

MediaActionSound mediaActionSound = new MediaActionSound();
mediaActionSound.play(MediaActionSound.SHUTTER_CLICK);

I've tested on more than ten devices. The problems are:

  1. The actually play a different sound that the built-in camera.
  2. Different devices actually play different sound. (It seems that the device manufacturer each has installed a different sound fine.)

There is some information about this file: /system/media/audio/ui/camera_click.ogg ... but I'm not sure if this is the sound file used. And if so, why do they all sound different and not the same as the built-in camera.

The solution I'm seeking:

Either:

Play exactly the same sound as with the built-in camera. How do I do this?

or

Install a custom sound file into my app and play this same sound across all devices. (However, this method is secondarily preferred because we have to find a custom sound file.)

Please advise.


Solution

  • If the default camera app has its own shutter sound, it's unlikely you can get to it - it's likely either baked into the app APK, or some custom addition to that OEM's set of device sounds that isn't visible to non-system apps.

    The main reason to use MediaActionSound to be compliant with the expectation in some countries that camera shutter sounds are not silenceable. MediaActionSound will still play a shutter sound even on a fully-silenced device in such countries, without the developer having to worry about it.

    Otherwise, you could just play whatever sound you want on shutter press, if complying with the shutter sound enforcement isn't critical - or you can use your own sound when shutter sound muting isn't enforced (you can check via canDisableShutterSound), and fall back to MediaActionSound in places where shutter sound shouldn't be silenced.