目前市面上的所有移动终端几乎都有camera应用,但android原生系统在静音模式下拍照是没有声音的,大部分国家的终端都有法规限制,如防止偷*拍,不管什么模式下拍照都应该发出快门音,针对此问题只要修改android原生frameworks/base/services/camera/libcameraservice/cameraservice.cpp中playSound函数即可,修改后的方法如下:
void CameraService::playSound(sound_kind kind) {
LOG1("playSound(%d)", kind);
Mutex::Autolock lock(mSoundLock);
sp<MediaPlayer> player = mSoundPlayer[kind];
if (player != 0) {
// do not play the sound if stream volume is 0
// (typically because ringer mode is silent).
int index;
AudioSystem::getStreamVolumeIndex(AudioSystem::ENFORCED_AUDIBLE, &index);
if (index != 0) {
AudioSystem::setStreamVolumeIndex(AudioSystem::ENFORCED_AUDIBLE,index);
player->seekTo(0);
player->start();
} else {
AudioSystem::setStreamVolumeIndex(AudioSystem::ENFORCED_AUDIBLE,7);
player->seekTo(0);
player->start();
usleep(300000);
AudioSystem::setStreamVolumeIndex(AudioSystem::ENFORCED_AUDIBLE,0);
}
}
}
void CameraService::playSound(sound_kind kind) {
LOG1("playSound(%d)", kind);
Mutex::Autolock lock(mSoundLock);
sp<MediaPlayer> player = mSoundPlayer[kind];
if (player != 0) {
// do not play the sound if stream volume is 0
// (typically because ringer mode is silent).
int index;
AudioSystem::getStreamVolumeIndex(AudioSystem::ENFORCED_AUDIBLE, &index);
if (index != 0) {
AudioSystem::setStreamVolumeIndex(AudioSystem::ENFORCED_AUDIBLE,index);
player->seekTo(0);
player->start();
} else {
AudioSystem::setStreamVolumeIndex(AudioSystem::ENFORCED_AUDIBLE,7);
player->seekTo(0);
player->start();
usleep(300000);
AudioSystem::setStreamVolumeIndex(AudioSystem::ENFORCED_AUDIBLE,0);
}
}
}
本文介绍了一种在Android系统中强制开启拍照声音的方法,通过修改原生系统的代码,确保无论设备处于何种模式下,拍照时都会发出声音,以此来防止非法拍摄行为。
6998

被折叠的 条评论
为什么被折叠?



