1

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.

ikevin8me
  • 4,253
  • 5
  • 44
  • 84

2 Answers2

1

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.

Eddy Talvala
  • 17,243
  • 2
  • 42
  • 47
  • The method canDisableShutterSound is not available in the Camera2 API, only on the deprecated Camera1 API. So how can we test for shutter sound enforcement without having to reference the old API? – PerracoLabs Jan 22 '18 at 01:38
  • Just use the deprecated API for the test; yes, that needs to be moved to a non-deprecated API, but works fine via Camera1. – Eddy Talvala Jan 22 '18 at 02:46
-1

It rely on your decision. If you want to make your app's brand, just use the one you like or treat the user with their familiar sound. Your don't have to complicate it

RootOnChair
  • 137
  • 10