如何在 Android 手机上静音相机快门声音

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10383083/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 03:28:44  来源:igfitidea点击:

How to mute camera shutter sound on android phone

androidaudioandroid-camera

提问by user430926

Is there any way to mute the camera shutter sound in Android (not rooted phone)?

有什么方法可以使 Android(非 root 手机)中的相机快门声音静音?

I use this code to mute my audio sound when taking picture:

我使用此代码在拍照时使我的音频静音:

  AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
    int streamType = AudioManager.STREAM_SYSTEM;
    mgr.setStreamSolo(streamType, true);
    mgr.setRingerMode(AudioManager.RINGER_MODE_SILENT);
    mgr.setStreamMute(streamType, true);

I mute the sound and silent the phone.

我把声音静音,让电话静音。

mCamera.takePicture(null, null, photoCallback); 

then take the picture

然后拍照

It's working on HTC HERO, HTC Desire, Motorola ME860, MotoA953. But when I tested it on Samsung Tab p1000and Sony Experia R800i, it's not working. Is there any other work around?

它正在处理HTC HERO, HTC Desire, Motorola ME860, MotoA953. 但是当我在Samsung Tab p1000和 上Sony Experia R800i对其进行测试时,它不起作用。有没有其他解决办法?

回答by Kimia Zhu

try this code:

试试这个代码:

AudioManager manager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
if(TextUtils.equals(muteMode, "mute")){
    manager.setStreamVolume(AudioManager.STREAM_SYSTEM, 0 , AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
}else{
    manager.setStreamVolume(AudioManager.STREAM_SYSTEM, manager.getStreamMaxVolume(AudioManager.STREAM_SYSTEM) , AudioManager.FLAG_ALLOW_RINGER_MODES);
}
//here continue to take picture...

do not use AudioManager.setStreamMute() method since there is a known issue on android below version 2.3..

不要使用 AudioManager.setStreamMute() 方法,因为在 2.3 以下版本的 android 上存在一个已知问题。

回答by David Snabel-Caunt

Since API level 17 (4.2) there is a proper, reliable way to do this, if the phone manufacturer supports it.

从 API 级别 17 (4.2) 开始,如果手机制造商支持,有一种适当、可靠的方法可以做到这一点。

First, detect whether you can disable the shutter sound programatically, then disable it

首先,检测是否可以通过编程方式禁用快门声音,然后禁用它

Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(id, info);
if (info.canDisableShutterSound) {
    mCamera.enableShutterSound(false)
}

You'll need to set id to the appropriate camera id in the call to Camera.getCameraInfo, or disable them all in a loop from 0 to Camera.getNumberOfCameras()- 1.

您需要在对 的调用中将 id 设置为适当的相机 ID Camera.getCameraInfo,或者在从 0 到Camera.getNumberOfCameras()- 1的循环中将它们全部禁用。

The developer documentationrecommends that you play another sound in place of the shutter sound, but you're not obliged to.

开发者文档建议您在地方快门声音再踢声音,但你并非必须。

回答by Jasjit Singh Marwah

The method you've posted already is actually the best one I can find/think of. The reason it doesn't work is because it's not supposed to. In fact, in many places (most of Europe, Japan, parts of US, etc.) it's illegal to disable the shutter sound. This is so that you can't take pictures in places you're not supposed to, and so you don't take pictures of people without their permission, and so on. It's just a shot in the dark that the manufacturer has purposely tried to make sure you can't do it no matter what (though technically there's always a way), but when you think about it, logically there's no reason your code shouldn't work right? It's simple, basic, makes sense. Anyways, there are many silent camera apps out there and Camera+ ICS is actually built on the default ICS camera but has a Silent Shutter option so it must be possible.

您已经发布的方法实际上是我能找到/想到的最好的方法。它不起作用的原因是因为它不应该。事实上,在许多地方(欧洲大部分地区、日本、美国部分地区等)禁用快门声音是非法的。这样你就不能在你不应该去的地方拍照,所以你不能在未经他们许可的情况下拍照,等等。制造商故意试图确保无论如何都无法做到这只是黑暗中的一个镜头(尽管从技术上讲总是有办法的),但是当您考虑它时,从逻辑上讲,您的代码没有理由不应该这样做工作对吗?这很简单,基本,有道理。无论如何,

回答by Rookie

there are a phones out there which play the shutter sound on their own. In this case, it seems to not be possible to disable the shutter sound.

有一部手机可以自己播放快门声。在这种情况下,似乎无法禁用快门声音。

回答by Abhi

One crazy way i can think is to get the permission to mute the phone.

我能想到的一种疯狂方法是获得将手机静音的许可。