How to play native camera sound on Android

后端 未结 6 1963
星月不相逢
星月不相逢 2020-12-29 21:29

I would like to play native camera shutter sound clip on camera preview capture. I\'m referring to the sound clip played when takePicture() is called.
How

6条回答
  •  心在旅途
    2020-12-29 21:56

    If the system file is there, you can use it like this:

    public void shootSound()
    {
        AudioManager meng = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
        int volume = meng.getStreamVolume( AudioManager.STREAM_NOTIFICATION);
    
        if (volume != 0)
        {
            if (_shootMP == null)
                _shootMP = MediaPlayer.create(getContext(), Uri.parse("file:///system/media/audio/ui/camera_click.ogg"));
            if (_shootMP != null)
                _shootMP.start();
        }
    }
    

提交回复
热议问题