【问题标题】:Stop recording audio when recording video in Google Glass在 Google Glass 中录制视频时停止录制音频
【发布时间】:2014-12-10 21:52:42
【问题描述】:

在 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》一书。 有什么想法吗??

【问题讨论】:

  • 是的,有可能。发布您现在拥有的录制代码,我可以帮助您。这也会使其他人受益。

标签: android google-glass


【解决方案1】:

几年前我有一个解决方案对我有用,但我的代码现在由于几次 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

【讨论】:

  • 我为我工作。我测试了大约 10 次,每次都有效。它录制时没有声音。你可能错过了一步。我只是提供了一个链接,以便您可以下载我正在运行的整个项目。让我知道它是否有效....
  • 我刚刚运行了您的代码,但我的 Glass 仍在录制声音。
  • 这很奇怪,因为它在我的 XE22 Glass 上工作。当您运行我上面发布的代码时,您是如何开始录制视频的?你在 Glass 上按了什么?
  • 真的很奇怪。我正在按下按钮进行长按。我没有在日志中看到任何“onLongPress”行:172 或“before start”第 177 行。行号来自您的代码,因为此代码都不会使我的视频捕获静音。 code
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-19
  • 1970-01-01
  • 1970-01-01
  • 2022-07-12
  • 1970-01-01
  • 2014-08-02
相关资源
最近更新 更多