[英]Android: Play camera shutter sound programmatically
I want to play camera shutter sound programmatically. 我想以编程方式播放相机快门声。 I'm not using ShutterCallback which automatically plays that sound, so I need to do it in some other way. 我没有使用自动播放声音的ShutterCallback,所以我需要以其他方式进行。 Anyone knows the solution? 谁知道解决方案?
MediaActionSound from API 16. 来自API 16的MediaActionSound 。
AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
switch( audio.getRingerMode() ){
case AudioManager.RINGER_MODE_NORMAL:
MediaActionSound sound = new MediaActionSound();
sound.play(MediaActionSound.SHUTTER_CLICK);
break;
case AudioManager.RINGER_MODE_SILENT:
break;
case AudioManager.RINGER_MODE_VIBRATE:
break;
}
Respect vibrate/silent mode in Android. 尊重Android中的振动/静音模式。
his resource explains how to play audio files 他的资源解释了如何播放音频文件
http://www.vogella.com/articles/AndroidMedia/article.html http://www.vogella.com/articles/AndroidMedia/article.html
You'll probably have to provide your own shutter sound effect. 您可能必须提供自己的快门音效。
If the system file is there, you can use it like this: 如果系统文件在那里,您可以像这样使用它:
public void shootSound()
{
AudioManager meng = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
int volume = meng.getStreamVolume( AudioManager.STREAM_NOTIFICATION);
if (volume != 0)
{
if (_shootMP == null)
_shootMP = MediaPlayer.create(getContext(), Uri.parse("file:///system/media/audio/ui/camera_click.ogg"));
if (_shootMP != null)
_shootMP.start();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.