Android Camera 拍照/攝像提示音

     其實,Camera 拍照/攝像提示音是爲了防止偷拍,業內有不成文規定,手機公司在作camera時,點擊拍照和錄像鍵的時候,必需要有提示音。所以,google也就很是人性化的將播放拍照聲音的函數,放到了cameraService中,防止開發者能開發出不響的camera,從而只要調用拍照函數,必定會響,這是寫死在framework中的。 函數

Camera真正播放提示音的是在CameraService.cpp中的playSound()方法,這個方法提供給拍照/攝像時調用。 google

// /frameworks/base/services/camera/libcameraservice/CameraService.cpp
void CameraService::playSound(sound_kind kind) {
    LOG1("playSound(%d)", kind);
    Mutex::Autolock lock(mSoundLock);
    sp<MediaPlayer> player = mSoundPlayer[kind];
    if (player != 0) {
        player->seekTo(0);
        player->start();
    }
}
下面就是在開始攝像時會調用playSound()方法播放提示音:
status_t CameraService::Client::startRecordingMode() {
    LOG1("startRecordingMode");
    status_t result = NO_ERROR;

    // if recording has been enabled, nothing needs to be done
    if (mHardware->recordingEnabled()) {
        return NO_ERROR;
    }
    // if preview has not been started, start preview first
    if (!mHardware->previewEnabled()) {
        result = startPreviewMode();
        if (result != NO_ERROR) {
            return result;
        }
    }
    // start recording mode
    enableMsgType(CAMERA_MSG_VIDEO_FRAME);
    mCameraService->playSound(SOUND_RECORDING);
    result = mHardware->startRecording();
    if (result != NO_ERROR) {
        LOGE("mHardware->startRecording() failed with status %d", result);
    }
    return result;
}
有時,攝像的同時會將這個提示音也錄入,要解決這個問題,能夠在mCameraService->playSOund(SOUND_RECORDING)後加一個延時,但這個延時不能用sleep()方法(會報一些莫名其妙的問題,直接就stopReCording),能夠用usleep()實現延時。


原文參考:http://blog.csdn.net/dyfleoo/article/details/7912021 spa

相關文章
相關標籤/搜索