在Google Glass中录制视频时停止录制音频

时间:2014-12-10 21:52:42

标签: android google-glass

在Google中录制视频时,有没有人在Intent或MediaRecorder中禁用声音 玻璃

我已从AndroidManifest中删除了权限,我没有在MediaRecorder中设置音频源,但我仍然录制音频。

我正在使用XE22。

    private boolean prepareVideoRecorder(){

    if (mCamera != null){
        mCamera.release();        // release the camera for other applications
    }       
    mCamera = getCameraInstance();
    if (mCamera == null) return false;

    mrec = new MediaRecorder();

    mCamera.unlock();

    mrec.setCamera(mCamera);
    //mrec.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
    CamcorderProfile profile = getValidCamcorderProfile();

    mrec.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    mrec.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mrec.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
    mrec.setVideoEncodingBitRate(profile.videoBitRate);
    mrec.setVideoEncoder(profile.videoCodec);

    mrec.setPreviewDisplay(mPreviewHolder.getSurface());

    mOutputFile = getOutputMediaFile(MEDIA_TYPE_VIDEO);
    mrec.setOutputFile(mOutputFile.toString());

    try {
        mrec.prepare();
    }
    catch (Exception e) {
        Log.e(TAG, e.getMessage());
        return false;
    }

    return true;
}

private CamcorderProfile getValidCamcorderProfile(){
    CamcorderProfile profile;

    if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_TIME_LAPSE_720P)){
        profile = CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_720P);
        return profile;
    }

    if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P))
        profile = CamcorderProfile.get(CamcorderProfile.QUALITY_720P);
    else
        profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);

    return profile;
}

该代码摘自Beginning Google Glass Development一书。 任何想法??

1 个答案:

答案 0 :(得分:0)

几年前我有一个解决方案对我有用,但由于多个API更新,我的代码现在崩溃了。经过几个小时的尝试和失败实验,我让它重新开始工作。

步骤:

1)删除有关音频的所有内容,例如 setVideoSource setAudioEncoder 。从您上面发布的代码。看起来你已经这样做了,但要从你的其余代码中验证一下。

2)将try catch添加到setProfile,你就可以了。   例如: 而不是做mrec.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH))

做的:

try {
    mrec.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
}catch (Exception e){

}

此外,请勿使用CamcorderProfile profile = getValidCamcorderProfile();。使用mrec.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH)),这应该有效。 同时从代码中删除以下内容

mrec.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);, mrec.setVideoEncodingBitRate(profile.videoBitRate);, mrec.setVideoEncoder(profile.videoCodec);.

在我的 prepareVideoRecorder() 功能中,这就是我的代码:

private boolean prepareVideoRecorder(){

    if (mCamera != null){
        mCamera.release();        // release the camera for other applications
    }
    mCamera = getCameraInstance();
    if (mCamera == null) return false;

    mrec = new MediaRecorder();

    mCamera.unlock();

    mrec.setCamera(mCamera);
    //mrec.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); Remove this
    mrec.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    //Add try catch to setProfile
    try {
     mrec.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
    }catch (Exception e){

    }

    mrec.setPreviewDisplay(mPreviewHolder.getSurface());

    mOutputFile = getOutputMediaFile(MEDIA_TYPE_VIDEO);
    mrec.setOutputFile(mOutputFile.toString());

    try {
        mrec.prepare();
    }
    catch (Exception e) {
        Log.e(TAG, e.getMessage());
        return false;
    }

    return true;
}

要从计算机 查看 记录视频 Glass ,您必须重新启动Glass

编辑: 从here获取我的整个项目。它从书中被修改为没有音频的记录。 https://github.com/InnoBlast/RecordingVideoWithoutSound