目前市面上的所有移动终端几乎都有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);
}
}
}