zmsoft / google-glass-api

Automatically exported from code.google.com/p/google-glass-api
0 stars 0 forks source link

MediaRecorder fails to capture video. #360

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Follow the official developer's guide to capture a video from the Camera:
http://developer.android.com/guide/topics/media/camera.html#capture-video

Code:
    mCamera = getCameraInstance();
    mMediaRecorder = new MediaRecorder();

    // Step 1: Unlock and set camera to MediaRecorder
    mCamera.unlock();
    mMediaRecorder.setCamera(mCamera);

    // Step 2: Set sources
    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    // Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
    mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));

    // Step 4: Set output file
    mMediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).toString());

    // Step 5: Set the preview output
    mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());

    // Step 6: Prepare configured MediaRecorder
    mMediaRecorder.prepare();

    // Step 7: Start recording
    mMediaRecorder.start(); // HERE it fails

What is the expected output? What do you see instead?
MediaRecorder to capture the video from the Camera object.
Instead MediaRecorder crashes and outputs the message: "MediaRecorder start 
failed: -19"

What version of the product are you using? On what operating system?
Google Glass, Android 4.0.4, XE12

Please provide any additional information below.
MediaRecorder error -19, if i am not mistaken, is the error for NO_INIT which 
would mean that the MediaRecorder is not properly initialized. I have tried 
almost all combinations of initializing the recorder but i still getting error 
-19. 
As i can see from here: 
https://code.google.com/p/google-glass-api/issues/detail?id=228&can=1&q=MediaRec
order&colspec=ID%20Type%20Status%20Priority%20Owner%20Component%20Summary
the problem was reported again and was not fixed. Capturing videos with an 
intent (using the CameraManager object) is a very limiting option for such a 
device.

Original issue reported on code.google.com by netcy...@gmail.com on 12 Jan 2014 at 8:52

GoogleCodeExporter commented 9 years ago

Original comment by ala...@google.com on 14 Jan 2014 at 12:15

GoogleCodeExporter commented 9 years ago
Has this issue been fixed yet? I saw a possible solution from here: 
http://stackoverflow.com/questions/20671932/mediarecorder-start-failed-19/211299
91#21129991 which didn't work for me as well. I, like the user who posted the 
original issue, have tried everything to try and get this to work to no avail. 
Or netcy, have you found a possible work around?

Thanks.

Original comment by lance.ok...@gmail.com on 21 Jan 2014 at 3:30

GoogleCodeExporter commented 9 years ago
it's still an issue for me, so I don't see it fixed myself. (sorry for the 
mee-too comment :)

Original comment by maroy.akos@gmail.com on 21 Jan 2014 at 5:51

GoogleCodeExporter commented 9 years ago
Unfortunately, i have found no fix either. I have sent my Glass for replacement 
and i hoped that the solution that the user found in stackoverflow was working. 
If any user find a fix, please post it asap.

Original comment by netcy...@gmail.com on 21 Jan 2014 at 5:53

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I had this problem when triggering a video capturing in my app while the video 
preview was live.  After much wailing and gnashing of teeth, I figured out that 
to start video capture on a previewing camera, I had to first completely stop 
the video preview.  This was accomplished with the following code, which I put 
of the top of my prepareVideoRecorder() implementation, prior to doing anything 
with a MediaRecorder:

    try {
        mCamera.setPreviewDisplay(null);
    } catch (java.io.IOException ioe) {
        Log.d(TAG, "IOException nullifying preview display: " + ioe.getMessage());
    }
    mCamera.stopPreview();
    mCamera.unlock();

Subsequently, I am able to capture video.  I am on XE12.

Original comment by josephba...@gmail.com on 21 Jan 2014 at 8:45

GoogleCodeExporter commented 9 years ago
can you post a more comprehensive / more complete code sample?

Original comment by maroy.akos@gmail.com on 22 Jan 2014 at 12:31

GoogleCodeExporter commented 9 years ago
#6 -- this answer worked perfectly for me. I could not thank you enough for 
your help...if I could upvote you I would. Instead, have a Gold Star (*) :) Now 
that I see that...I am hitting myself in the head.

#7 -- you can use http://developer.android.com/guide/topics/media/camera.html 
to help you.

Original comment by lance.ok...@gmail.com on 22 Jan 2014 at 12:39

GoogleCodeExporter commented 9 years ago
Comment #6 worked for me too! Thank you!

This is still a bug since the same code (without nullifying the previewing 
camera) works fine on other Android devices. Also, the official documentation 
does not mention this. At least we have a workaround. 

Original comment by netcy...@gmail.com on 22 Jan 2014 at 8:13

GoogleCodeExporter commented 9 years ago
trying to merge #6 with the original code sample above: I would but the code 
from #6 just above the mCamera.unlock() code in the original code sample (on 
top of this bug ticket)?

Original comment by maroy.akos@gmail.com on 22 Jan 2014 at 8:28

GoogleCodeExporter commented 9 years ago
#9: I agree with you completely that it is a Glass Issue. I too was using the 
same code for a tablet version, and had to remove that nullifying part. Very 
interesting, annoying bug that I'm glad with everyone's help the issue was 
solved.

#10: You put the code that #6 gave before you do anything with MediaRecorder, 
as stated.

Original comment by lance.ok...@gmail.com on 25 Jan 2014 at 7:51

GoogleCodeExporter commented 9 years ago
#6 - your solution works! Thanks! (Sony Ericsson Xperia Pro, android 2.3.4)

Original comment by kolobcha...@gmail.com on 9 Feb 2014 at 5:15

GoogleCodeExporter commented 9 years ago
#6 worked for me on XE12 but now on XE16, Glass does a total reboot upon 
stopPreview...didn't think an app could take down the whole OS...

Original comment by jared.ma...@gmail.com on 21 Apr 2014 at 4:13

GoogleCodeExporter commented 9 years ago
I'm also getting crashes with MediaRecorder since XE16... :(

Original comment by aregnie...@gmail.com on 21 Apr 2014 at 7:03

GoogleCodeExporter commented 9 years ago
And I'm getting them on taking pictures

Original comment by eug...@wearableintelligence.com on 21 Apr 2014 at 7:04

GoogleCodeExporter commented 9 years ago
I was seeing the hard crash on XE16 using this fix as well.  I made some tweaks 
and everything went back to working:

try {
    mCamera.stopPreview();
    mCamera.setPreviewDisplay(null);
    } catch (java.io.IOException ioe) {
        Log.d(TAG, "IOException nullifying preview display: " + ioe.getMessage());
    }
    mCamera.unlock();

Stopping the preview then nulling things out seemed to do the trick for me.

Original comment by andrew.r...@gmail.com on 24 Apr 2014 at 10:36

GoogleCodeExporter commented 9 years ago
#16 works for XE16 - thank you!!!

Original comment by jared.ma...@gmail.com on 25 Apr 2014 at 2:02

GoogleCodeExporter commented 9 years ago
Hi,

For me MediaRecorder fails with an IllegalStateException - start called in an 
invalid state: 1. I'm pretty sure I'm calling MediaRecorder.start() after 
MediaRecorder.prepare(). I have tried to call start() after a lag of 5 seconds 
in case prepare()'s taking time, but it didn't help. Any ideas where I might be 
going wrong/how to fix this?

Thanks a lot!

Original comment by sreyasi...@gmail.com on 23 Jun 2014 at 3:13

GoogleCodeExporter commented 9 years ago
Also wanted to mention: I'm on XE18.11 and the fix stated here doesn't solve 
the issue (naturally, because this seems to be a different problem).

Original comment by sreyasi...@gmail.com on 23 Jun 2014 at 3:20

GoogleCodeExporter commented 9 years ago
For info i'm on XE18.11, and the #16 work perfectly for me. THKSSSSS

Original comment by stephane...@gmail.com on 24 Jun 2014 at 4:15

GoogleCodeExporter commented 9 years ago
The issue being discussed here and also the fix #16 is for the error: 
"MediaRecorder start failed: -19", but the error I am getting is "start called 
in an invalid state: 1". Can someone please explain possible reasons as to why 
this is happening?

Original comment by sreyasi...@gmail.com on 25 Jun 2014 at 11:43

GoogleCodeExporter commented 9 years ago
Hey all!

My issue is fixed. Here's a brief summary:

Initially I was calling mMediaRecorder.start() in my onClick() method after a 
call to the prepareVideoRecorder() method just as described in the developer 
guide 
(http://developer.android.com/guide/topics/media/camera.html#capture-video). 
This resulted in the IllegalStateException error. But when I called 
mMediaRecorder.start()just after mMediaRecorder.prepare() like #1 did, along 
with fix #16, it worked!

I wish someone could explain why this happened. Is it possible that media 
recorder quickly slid into idle state in between calls? It's strange!

Thanks!

Original comment by sreyasi...@gmail.com on 27 Jun 2014 at 1:42

GoogleCodeExporter commented 9 years ago
Does anyone could share a code that actually do work for video recording? I 
didn't find any that is not bugged.
Thanks

Original comment by mathi...@gmail.com on 13 Jul 2014 at 8:26

GoogleCodeExporter commented 9 years ago
I also met this problem , this is all my code :

   mCamera = Camera.open();
            try {
                mCamera.stopPreview();
                mCamera.setPreviewDisplay(null);
            } catch (java.io.IOException ioe) {
                MelonLogger.e(ioe);
            }
            mCamera.unlock();

  mrec = new MediaRecorder();  // Works well
            mrec.setCamera(mCamera);
            mrec.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
            mrec.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
            // need a solid file uploading task
            mrec.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_480P));

            String dir = MelonPathManager.getInstance().getUserSubDirByIdAndType(MelonMyInfoManager.getInstance()._getInt(MelonMyInfoManager.PREFIX_USER_ID, MelonConst.PREF.DEFAULT_INT), MelonConst.FileType.VIDEO);
            String path = dir + System.currentTimeMillis() + ".mp4";
            MelonFileManager.checkPath(dir);
            filePath = path;

            mrec.setOutputFile(path);
            mrec.setPreviewDisplay(surfaceHolder.getSurface());
            mrec.prepare();

            mrec.start();

Seems not working, I am following the previous provided solution , now it gives 
me a error about : IMediaDeathNotifier﹕ media server died  

Original comment by zh...@garena.com on 22 Jul 2014 at 2:49

GoogleCodeExporter commented 9 years ago
FYI: I had some code that was working with XE18.3, but it is not working 
anymore with XE19.1 (I have the same error as #24 ):
https://code.google.com/p/google-glass-api/issues/detail?id=578

Original comment by marco.bu...@gmail.com on 23 Jul 2014 at 3:35

GoogleCodeExporter commented 9 years ago
Can't record with 19.1 either.

Original comment by hannings...@gmail.com on 29 Jul 2014 at 4:36

GoogleCodeExporter commented 9 years ago
I'm having the same problem on 19.1. I cannot record a video, even when usint 
the trick of setting up the previewDisplay to null.

Original comment by extros...@gmail.com on 17 Aug 2014 at 10:55

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Is there a solution for XE22?

Original comment by chenfang...@gmail.com on 13 Jan 2015 at 2:15

GoogleCodeExporter commented 9 years ago
#6 I love you. Worked for me

Original comment by oscarji...@gmail.com on 10 Mar 2015 at 8:27