Camera with custom shutter sound

I have the usual camera implementation that I would like to have my own sound when the picture is taken using API 10. I have the following code that makes play my sound , but it also plays the default camera sound, I only need to play the sound from the camera, not the default.

  //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(); } }; 
+6
source share
1 answer

Try it,

 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 taller than onShutter() , then call media.start() on onShutter()

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

+7
source

Source: https://habr.com/ru/post/949376/


All Articles