Android: takePicture() not making sound
I also had this problem. I solved it by using following code:The following is used to call takePicture:
clickButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View view) { mCamera.takePicture(shutterCallback, null, onPicTaken); } });
Now shutteerCallBack:
private final ShutterCallback shutterCallback = new ShutterCallback() { public void onShutter() { AudioManager mgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mgr.playSoundEffect(AudioManager.FLAG_PLAY_SOUND); } };
Now Do whatever after taking picture from camera:
/** * This will be called after taking picture from camera. */ final transient private PictureCallback onPicTaken = new PictureCallback() { /** * After taking picture, onPictureTaken() will be called where image * will be saved. * */ @Override public void onPictureTaken(final byte[] data, final Camera camera) { }
This will play sound on clicking capture button.
Thank you :)
If you want a camera to play the default android sound, you have to give it an empty shutter callback.
ShutterCallback shutterCallback = new ShutterCallback() { @Override public void onShutter() { /* Empty Callbacks play a sound! */ }};mCamera.takePicture(shutterCallback , null, onPicTaken);
Tested on HTC One SV and Samsung Galaxy XCover 2.
You give the callback an empty shutter callback and then it plays the default sound.
If you call takePicture
with a null ShutterCallback
the camera won't play any sound.
The answer of Shrikant is working, but might behave unexpectedly as mgr.playSoundEffect();
is not intended to be called with AudioManager.FLAG_PLAY_SOUND
as the doc states.