简体   繁体   English

禁用相机快门声音,AudioManager在三星中不起作用

[英]Disable Camera Shutter Sound, AudioManager not working in Samsung

I disabled the camera shutter sound like this: 我禁用了相机的快门声,如下所示:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
     mgr.setStreamVolume(AudioManager.STREAM_SYSTEM,0,0);
     mgr.adjustStreamVolume(AudioManager.STREAM_SYSTEM,AudioManager.ADJUST_MUTE, 0);
 } else {
     mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true);
}

This works great for most of my testdevices. 这对我的大多数测试设备都适用。

If my systemwide soundoptions are on loud, i can disable and enable the shutter sound in my apps settings. 如果系统范围内的声音选项很大,我可以在应用程序设置中禁用和启用快门声。

I testet on a Samsung A3(2016) and a Samsung S7 as well and the shutter sound is always on maximum. 我在三星A3(2016)和三星S7上进行了测试,并且快门声音始终处于最大状态。 When I totally mute all the sounds in my systemsettings outside the application - still, the shutter sound is there. 当我完全静音应用程序外部系统设置中的所有声音时-仍然存在快门声音。 Also if I disable the shutter sound with the code snippet from above inside the app, on Samsung devices the shutter sound is played. 另外,如果我在应用程序内部从上面禁用带有代码片段的快门声音,则在三星设备上会播放快门声音。

I tried to mute all flags: 我试图使所有标志静音:

int streams = AudioManager.STREAM_ALARM|
              AudioManager.STREAM_DTMF|
              AudioManager.STREAM_MUSIC|     
              AudioManager.STREAM_NOTIFICATION|
              AudioManager.STREAM_RING|
              AudioManager.STREAM_SYSTEM|
              AudioManager.STREAM_VOICE_CALL; 

mgr.adjustVolume(AudioManager.ADJUST_MUTE, streams);

Still the same result. 结果还是一样。

Can anyone tell me, what I'm missing here? 谁能告诉我,我在这里想念的是什么? Is Samsung using some sort of different Audiostream? 三星在使用某种不同的Audiostream吗?


EDIT 1: I added the following code in order to check if the code snippet from above is changing anything: 编辑1:我添加了以下代码,以检查上面的代码片段是否发生了更改:

int streamMuted = mgr.getStreamVolume(AudioManager.STREAM_SYSTEM);

mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true);

Boolean volumeFixed = mgr.isVolumeFixed();
streamMuted = mgr.getStreamVolume(AudioManager.STREAM_SYSTEM);

The output here is that the STREAM_SYSTEM has the StreamVolume '6' in the beginning, then I'm Muting this Stream. 这里的输出是STREAM_SYSTEM的开头有StreamVolume'6',然后我将这个Stream静音。 After that I'm checking if the device implements a fixed volume policy, which is 'false'. 之后,我要检查设备是否实施了固定的卷策略,即“ false”。 After checking the StreamVolume again, it has the value '0'. 再次检查StreamVolume后,其值为'0'。

So can it be that the shutter sound has a completely different AudioStream, even when I use the default system camera, the shutter sound can be disabled by muting the System Sound Settings? 因此,即使我使用默认的系统摄像机,快门声音是否具有完全不同的AudioStream,可以通过静音系统声音设置来禁用快门声音吗?

Shutter sound could be hardware/manufacturer dependant. 快门声可能取决于硬件/制造商。 In some Android versions/ROM the shutter sound cannot be disabled. 在某些Android版本/ ROM中,无法禁用快门音。 You could try to enable the "DoNotDisturb" mode just before take the photo, but it's not guaranteed to work well. 您可以在拍摄照片之前尝试启用“ DoNotDisturb”模式,但不能保证它能正常工作。

Update 更新资料

There could be three other solutions to try just before take the photo: 拍照之前,可能还有其他三种解决方案:

  • mute the hidden "AudioManager.STREAM_SYSTEM_ENFORCED" streamType (using Reflection) 使隐藏的“ AudioManager.STREAM_SYSTEM_ENFORCED” streamType静音(使用反射)
  • set "AudioManager.setSpeakerphoneOn(false)" 设置“ AudioManager.setSpeakerphoneOn(false)”
  • temporarily disable the Speaker using the hidden "android.media.AudioSystem.setDeviceConnectionState()" (pay attention that this procedure will set the Speaker OFF for ALL ANDROID SYSTEM so it's very dangerous if not well managed and then not well restored to the previous value when done) 使用隐藏的“ android.media.AudioSystem.setDeviceConnectionState()”暂时禁用扬声器(请注意,此过程会将所有ANDROID系统的扬声器设置为OFF,因此,如果管理不当,然后无法很好地还原为先前的值,则非常危险完成后)

把它放进你的清单

  <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

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

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