开发者

MediaRecorder Prepare Failed

开发者 https://www.devze.com 2022-12-27 02:05 出处:网络
I\'m new here. I have been trying to create a video capture app using the android emulator without much success. As far as I know and looking through all the samples and code on the internet (this sit

I'm new here. I have been trying to create a video capture app using the android emulator without much success. As far as I know and looking through all the samples and code on the internet (this site and others), I must still be missing a step.

I've tried using this sample near the end of this thread made by JonPro: http://www.anddev.org/viewtopic.php?p=24723#24723

and I've tried making my own but the media recorder would always fail on the prepare stage with the most unhelpful message of 'prepare failed'. I have no clue what I am missing. I seem to have the correct permissions and a SDCard is mounted according to the emulator. Should I be us开发者_JS百科ing a android SDK version other than 2.1?

Even though the code in that forum claims to work, I figured out that this line was missing: recorder.setCamera(camera);

But still no joy as the logs shows that: 'Failed to get camera(0x16b70) parameters' when prepare() is called but it still doesn't make sense as the preview is okay, but no recording! Any help or suggestions will be appreciated.

Edit: Can anyone confirm that this can work for the SDK and the emulator? or I'm I wasting my time trying to get this to work in this version. Am I able to get the source code for the prepare function as it is OpenSource?


The fix for this problem is mCameraDevice.unlock() must be set before prepare. It's important that this is set after mCameraDevice.setPreviewDisplay(mHolder);

example:

/*--------------------------------------surfaceCreated---------------------------------------------*/
/**
 * Surface Created sets that the surface is created.
 */
 public void surfaceCreated(SurfaceHolder arg0) {
     // TODO Auto-generated method stu1595
        try {
            Log.d(LOG_TAG, "setPreviewDisplay enter");
            mCameraDevice.setPreviewDisplay(mHolder);
            Log.d(LOG_TAG, "setPreviewDisplay exit");
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        mCameraDevice.unlock();
        Log.d("*************", "***********unlock()****");
     isSurfaceCreated = true;


 }

BR P.N


recorder.setVideoSize(176, 144);
recorder.setVideoFrameRate(20);
recorder.setAudioChannels(1);
recorder.setPreviewDisplay( mHolder.getSurface());

this helped for me. Look in logcat during debug

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号