简体   繁体   English

相机具有自定义快门声音

[英]Camera with custom shutter sound

I have a custom camera implementation which I would like to have have my own sound when the picture is taken using API 10. I have the following code which does play my sound but it also plays the default camera sound as well, I need to only play my camera sound and not the default one. 我有一个自定义camera实现,当我使用API​​ 10拍摄照片时,我想拥有自己的声音。我有以下代码可以play my sound但它也播放默认的相机声音,我只需要播放我的相机声音而不是默认声音。

   //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();
    }
};

Try this, 试试这个,

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 the above before onShutter() then call media.start() on onShutter() 前做上述onShutter()然后调用media.start()onShutter()

then on onPictureTaken() Do the following. 然后on onPictureTaken()执行以下操作。

public void onPictureTaken(byte[] data, Camera camera) {


        if (isVolumeChanged){
            audio.setStreamVolume(AudioManager.STREAM_SYSTEM,currentVolume,AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
        }
    }      

Hope this helps!!!!! 希望这可以帮助!!!!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM