有什么方法可以替换或静音 Android 中的相机快门声音吗?
我想用代码中的其他声音替换快门声音(相机拍照时发出的声音)。我希望它能像铃声或通知一样,但我没有看到任何其他的东西。我见过在拍照之前将手机静音的代码,并在拍照后立即取消静音,但我更愿意用另一个 mp3 或 ogg 替换声音。
了解如果您有 root 的手机,则可以替换该文件。这不是我的应用程序的解决方案。
就在我的应用程序中。想法是设置它,然后取消设置。有趣的是,当你输入一些内容后,重新阅读它,它有助于从不同的角度思考它。我已经使用下面的代码关闭了音频服务,并且我之前就播放了声音。作为一个很好的解决方法。也许有一天,我们能够设置它。
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true);
谢谢!
I'd like to replace the shutter sound (the sound the camera makes when snapping a photo) with something else in code. I was hoping it would be like ringtones or notifications, but I don't see anything anywhere other about it. I've seen code to silence the phone right before taking the pic, and unsilencing it right after, but I'd prefer to replace the sound with another mp3 or ogg.
Understand if you have a rooted phone, you can replace the file. This is not a solution for my app.
Just in my app. Idea would be to set it, then unset it. Funny how after you type something out, re-read it, it helps think of it from a different perspective. I've used the code below to shut down the audio service, and I play my sound right before. Works as a great workaround. Perhaps someday, we'll be able to set it.
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true);
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用的是
Camera
对象,则可以提供Camera.ShutterCallback
并播放您想要的任何内容。如果您使用
Intent
启动另一个应用来拍照,则该应用可以选择拍照时播放的内容。您的音频静音解决方案是对用户不利的,就好像在该时间段内有任何其他需要播放系统声音的内容一样,用户将听不到它。
If you are using the
Camera
object, you can supply aCamera.ShutterCallback
and play whatever you want.If you are using an
Intent
to launch another app to take the picture, that app gets to choose what it plays when the picture is taken.Your mute-the-audio solution is user-hostile, as if there is anything else that needs to play a system sound during that period of time, the user won't hear it.
您可以使用预览回调中的数据,使用 onclick 侦听器,通过函数将其保存在某种类型的触发器(例如按钮)上的图片中。您可以将图像压缩为 jpeg 或 png。这样就不需要实现shutterCallback了。因此,您可以在拍照时播放任何您想要的声音或不播放任何声音。
You may use the data from the preview callback using a function to save it at a picture on some type of trigger such as a button, using onclick listener. you could compress the image to jpeg or png. In this way, there no shutterCallback to be implemented. and therefore you can play any sound you whant or none when taking a picture.