Set Camera shoot Sound - Android Camera

Android examples for Camera:Camera Attribute

Description

Set Camera shoot Sound

Demo Code


//package com.java2s;

import android.content.Context;

import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;

public class Main {
    public static void shootSound(Context context) {
        AudioManager meng = (AudioManager) context
                .getSystemService(Context.AUDIO_SERVICE);
        int volume = meng.getStreamVolume(AudioManager.STREAM_NOTIFICATION);

        MediaPlayer _shootMP = null;//ww w  . j a  v a 2s  . c  om

        if (volume != 0) {
            if (_shootMP == null)
                _shootMP = MediaPlayer
                        .create(context.getApplicationContext(),
                                Uri.parse("file:///system/media/audio/ui/camera_click.ogg"));
            if (_shootMP != null)
                _shootMP.start();
        }
    }
}

Related Tutorials