Android Capture视频mediaRecorder.start()失败-19

时间:2012-12-05 23:28:29

标签: android camera android-mediarecorder

我需要录制视频并保存,但我的媒体录制器start()方法出错:失败 - 19 (这个错误到底是什么?没有评论在文档中:() 我第二天正在与这个错误作斗争,我已经尝试了多个代码(谷歌教程,英特尔样本......)我在网上找到了,但无法完成任何工作。请帮我找出导致问题的原因。我甚至开始怀疑我的手机(SE live,wt19i)是否能够录制视频(但默认的相机应用可以正常工作)。真的,,有没有人知道我应该尝试/检查/修复

以下是我的录音代码:

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

我在清单文件中有相机,存储卡和音频的许可请求。我已将 minSdkVersion 设置为10并定位到15

这是 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)

编辑:

我正在添加我的清单文件:

<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

我已经尝试过运行此应用 我的 cousins mob (其SE,但另一种型号)和它没有任何问题。由于我的手机没有Android更新,我试图通过原始的“索尼电脑配套”软件“修复”它。我希望它会在它之后工作,因为我猜不可能在没有“hack”的情况下降级android版本

EDIT3

我尝试升级甚至降级手机上的固件。什么也没有变。我正在考虑撰写客户支持或XDA论坛,并要求任何使用同一部手机的人尝试运行它。

2 个答案:

答案 0 :(得分:1)

一步一步地开发它。 从默认值开始。

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

如果您未指定视频尺寸,则仍会出现错误。 如果您没有管理预览大小的实现。尝试使用固定大小,它应该工作:

mMediaRecorder.setVideoSize(320, 240);

答案 1 :(得分:0)

我找不到有关错误-19的文档。但是,您似乎并没有要求所有必需的权限。start failed错误有时是由于缺少权限:

尝试添加的可能权限是:

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

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