2014-12-10 138 views
1

在Google中录制视频时是否有人在Intent或MediaRecorder中禁用声音 Glass?在Google Glass中录制视频时停止录制音频

我已经从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; 
} 

该代码取自“开始Google Glass开发”一书。 任何想法?

+0

是的,这是可能的。发布您现在拥有的录音代码,我可以帮助您。这也会让其他人受益。 – Programmer 2014-12-18 19:23:57

回答

0

我曾经有一个解决方案在几年前就已经为我工作了,但是由于几个API更新,我的代码现在崩溃了。经过数小时的尝试和失败实验,我已经开始重新开始工作。

步骤:

1)删除有关音频的内容,如setVideoSourcesetAudioEncoder。从你上面发布的代码。它看起来像你已经这样做,但从其他代码验证。

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; 
} 

看到录制视频玻璃从您的电脑,您必须重新启动玻璃

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

+0

我已经完成了你的建议,但我仍在录制音频 – user283243 2014-12-21 23:04:27

+0

我为我工作。我测试了大约10次,每次都有效。它没有声音记录。你可能错过了一步。我刚刚提供了一个链接,以便您可以下载我正在运行的整个项目。让我知道它是否工作.... – Programmer 2014-12-22 05:00:49

+0

我刚刚运行您的代码,仍然是我的Glass记录声音。 – user283243 2014-12-22 15:27:43