How to play native camera sound on Android

后端 未结 6 1925
星月不相逢
星月不相逢 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:41

    You may want to use SoundPool

    SoundPool soundPool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 0);
    int shutterSound = soundPool.load(this, R.raw.camera_click, 0);
    

    and then to play the sound

    soundPool.play(shutterSound, 1f, 1f, 0, 0, 1);
    

    Check out http://developer.android.com/reference/android/media/SoundPool.html to understand the parameters.

    You will need a media file called camera_click.ogg in your project at res/raw. You should be able to use the Android default sound which can be obtained from the Android open source project in the following location ( frameworks/base/data/sounds/effects/camera_click.ogg ) if your project is licensed under the Apache license. If your project isn't licensed under the Apache license I have no idea if you can use it or not. I am not a lawyer.

提交回复
热议问题