Android Capture video mediaRecorder.start() failed -19

删除回忆录丶 提交于 2020-01-13 02:41:12

问题


I need to record the video and save it but I get error on start() method of media recorder: failed - 19 (what is this error supposed to be? There is no comment on it in documentation :( ) I'm fighting with this error second day, I have tried multiple codes (google tutorial, intel sample, ...) I found all over the web, but couldn't make work any of them. Please help me find what is causing the problem. I'm even starting to doubt that my mobile phone (SE live, wt19i ) is capable of recording the video (but default camera app works fine). Really, please, does anybody have any idea what should I try/check/fix?

Here is my code for recording:

public boolean record()
        {
            // if already recording, return
            if( recording ) return false;

            // We are recording
            recording = true;
            // log start of the method
            System.out.println("CameraPreview::record() - Method start");

            // Have tried to stop preview before record - didnt help
            //mCamera.stopPreview();
            mCamera.unlock();

            mRecorder = new MediaRecorder();
            // have tried this listener to get some extra info (doesnt work)
            mRecorder.setOnErrorListener(new MediaRecorder.OnErrorListener() {              
                public void onError(MediaRecorder mr, int what, int extra) {
                    System.out.println("MediaRecorder::onError listener:"+what+" - "+extra);

                }
            });


            mRecorder.setCamera(mCamera);

            // Set media recorder properties
            mRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
            mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

            mRecorder.setProfile( CamcorderProfile.get( CamcorderProfile.QUALITY_LOW ) );
            // have tried to set format without profile - didnt help
            //mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
            //mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
            //mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);

            mRecorder.setOutputFile("/sdcard/MVR_video.3gp");
            mRecorder.setPreviewDisplay(mHolder.getSurface());

            // Prepare media recorder
            try {
                mRecorder.prepare();
            } catch (Exception e) {
                Log.d("MyVideoRecord", "Error preparing media recorder: " + e.getMessage());
                System.out.println("CameraPreview::record() - prepare() thrown an exception");

                stopRecord();
                return false;
            }

            // Have tried to wait until prepare is done - didnt help
            try {Thread.sleep(1000); } catch( Exception e){}
            try {
                mRecorder.start();
            } catch (Exception e) {
                Log.d("MyVideoRecord", "Error starting media recorder: " + e.getMessage());
                System.out.println("CameraPreview::record() - start() thrown an exception");
                System.out.println("Exception: "+e.getMessage());
                e.printStackTrace();

                stopRecord();
                return false;
            }

            System.out.println("CameraPreview::record() - Method returning TRUE");
            return true;
        }

I have permission requests for camera, memory card and audio in manifest file. I have set minSdkVersion to 10 and target to 15

Here is LogCat

I/System.out(3990): CameraPreview::record() - Method start
I/MediaRecorderJNI(3990): prepare: surface=0x1f8e10 (identity=171)
E/MediaRecorder(3990): start failed: -19
D/MyVideoRecord(3990): Error starting media recorder: start failed.
I/System.out(3990): CameraPreview::record() - start() thrown an exception
I/System.out(3990): Exception: start failed.
W/System.err(3990): java.lang.RuntimeException: start failed.
W/System.err(3990):     at android.media.MediaRecorder.start(Native Method)
W/System.err(3990):     at com.example.myvideorecord.CameraPreview.record(CameraPreview.java:142)
W/System.err(3990):     at com.example.myvideorecord.MainActivity.onOptionsItemSelected(MainActivity.java:101)
W/System.err(3990):     at android.app.Activity.onMenuItemSelected(Activity.java:2502)
W/System.err(3990):     at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:969)
W/System.err(3990):     at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
W/System.err(3990):     at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
W/System.err(3990):     at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
W/System.err(3990):     at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:468)
W/System.err(3990):     at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:126)
W/System.err(3990):     at android.view.View$PerformClick.run(View.java:14263)
W/System.err(3990):     at android.os.Handler.handleCallback(Handler.java:605)
W/System.err(3990):     at android.os.Handler.dispatchMessage(Handler.java:92)
W/System.err(3990):     at android.os.Looper.loop(Looper.java:137)
W/System.err(3990):     at android.app.ActivityThread.main(ActivityThread.java:4441)
W/System.err(3990):     at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(3990):     at java.lang.reflect.Method.invoke(Method.java:511)
W/System.err(3990):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
W/System.err(3990):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
W/System.err(3990):     at dalvik.system.NativeStart.main(Native Method)

EDIT:

I'm adding my manifest file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myvideorecord"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
        android:debuggable="true" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main"
            android:screenOrientation="landscape" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".CameraPreview"
            android:screenOrientation="landscape"
            ></activity>
    </application>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-feature android:name="android.hardware.camera" />
</manifest>

EDIT2

I have tried run this app on my cousins mob (its SE, but another model) and it worked without any problem. As there isnt android update for my phone, Im trying to to "repair" it through original "Sony pc companion" software. I hope it will work after it as I guess it is not possible to downgrade the android version without any "hack"

EDIT3

I have tried to upgrade and even downgrade firmware on my mobile. Nothing has changed. I'm considering writing on customer support or XDA forum and ask anybody with the same phone to try to run it.


回答1:


Develop it step by step. Begin from the default values.

mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
//Use values from available Camera preview sizes 
mMediaRecorder.setVideoSize(mCameraPreview.getPreviewWidth(), mCameraPreview.getPreviewHeight());
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);

You'll still have errors if you don't specify video size. If you don't have implementation of managing preview sizes. Try it with fixed size, It should work:

mMediaRecorder.setVideoSize(320, 240);



回答2:


I can't find documentation on error -19. However, it looks like you're not asking for all needed permissions.The start failed error is sometimes due to a missing permission:

Possible permissions to try to add are:

<uses-feature android:name="android.hardware.microphone"/>

and

<uses-permission android:name="android.permission.STORAGE" />


来源:https://stackoverflow.com/questions/13734406/android-capture-video-mediarecorder-start-failed-19

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!