Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera with custom shutter sound

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();
    }
};
like image 334
kabuto178 Avatar asked Jul 13 '13 16:07

kabuto178


1 Answers

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!!!!!

like image 138
Dulanga Avatar answered Sep 20 '22 14:09

Dulanga