Camera with custom shutter sound
android, android-camera
Solution
Try this,
if (android.os.Build.VERSION.SDK_INT>=android.os.Build.VERSION_CODES.JELLY_BEAN_MR1){
camera.enableShutterSound(false);
}
else{
AudioManager audio= (AudioManager)this.getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
currentVolume=audio.getStreamVolume(AudioManager.STREAM_SYSTEM);
audio.setStreamVolume(AudioManager.STREAM_SYSTEM, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
MediaPlayer media= MediaPlayer.create(SecondCamera.this,R.raw.camera_click);
media.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
isVolumeChanged=true;
}
Do the above before `onShutter()` then call `media.start()` on `onShutter()`
then on `onPictureTaken()` Do the following.
public void onPictureTaken(byte[] data, Camera camera) {
if (isVolumeChanged){
audio.setStreamVolume(AudioManager.STREAM_SYSTEM,currentVolume,AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
}
}
Hope this helps!!!!!
Problem
I have a custom `camera` implementation which I would like to have have my own sound when the picture is taken using API 10. I have the following code which does `play my sound` but it also plays the default camera sound as well, I need to only play my camera sound and not the default one. ``` //takes picture mCamera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG); ShutterCallback myShutterCallback = new ShutterCallback() { @Override public void onShutter() { MediaPlayer.create(SecondCamera.this,R.raw.camera_click).start(); } }; ```