1

Has anyone disabled sound in either Intent or MediaRecorder when record video in Google Glass?

I have removed permissions from AndroidManifest and I am not setting the audio source in MediaRecorder but I still record audio.

I am using 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;
}

The code is taken from the book Beginning Google Glass Development. Any Ideas??

user283243
  • 13
  • 4
  • Yes, it is possible. Post the recording code you have now and I can help you. This will benefit other people too. – Programmer Dec 18 '14 at 19:23

1 Answers1

0

I had a solution that worked before for me few years ago but my code is now crashing due to several API updates. Withing hours of try and fail experiment, I got it to start working again.

Steps:

1) Remove anything about audio such as setVideoSource and setAudioEncoder. From the code you posted above. It looks like you already did that but verify that from the rest of your code.

2) Add try catch to setProfile and you are fine to go. For example: Instead of doing mrec.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH))

do:

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

}

Furthermore, don't use CamcorderProfile profile = getValidCamcorderProfile();. Use mrec.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH)) and that should work. Also remove the following from your code

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

Inside my prepareVideoRecorder() function, this is what my code looks like:

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

To see the recorded video on Glass from your computer, you have to restart Glass.

EDIT: Get my whole project from here. Its from the book and was modified to record without audio. https://github.com/InnoBlast/RecordingVideoWithoutSound

Programmer
  • 121,791
  • 22
  • 236
  • 328
  • I works for me. I tested it about 10 times and it worked each time. It records with no sound. You probably missed a step. I just provided a link so that you can download my whole project that is working. Let me know if it worked.... – Programmer Dec 22 '14 at 05:00
  • I have just run your code and still my Glass records sound. – user283243 Dec 22 '14 at 15:27
  • That's weird because it is working on my XE22 Glass. When you run the code I posted above, how did you start to record the video? What did you press on Glass? – Programmer Dec 22 '14 at 21:10
  • It is really weird. I am pressing the button for long press. I have not seen in the logs any "onLongPress" line: 172 or "before start" line 177. The line numbers are from your code as neither this code is muting my video capture. `code` – user283243 Jan 12 '15 at 22:46