Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: takePicture() not making sound

Tags:

I am using the takePicture() method from the Camera class. It takes the picture , but it makes no sound! My client wants the default click sound that Android makes.

I have seen other threads and it seems that the problem is in disabling the sound, not the opposite! Why is it that my app is not making the click sound??

like image 609
Bitcoin Cash - ADA enthusiast Avatar asked Jun 05 '12 04:06

Bitcoin Cash - ADA enthusiast


1 Answers

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 :)

like image 160
Shrikant Ballal Avatar answered Nov 10 '22 15:11

Shrikant Ballal