【问题标题】:Desperate Help Needed on media recorder媒体记录器急需帮助
【发布时间】:2018-03-16 22:36:29
【问题描述】:

我正在尝试使用 mediarecorder 创建一个简单的摄像机应用程序。程序不断崩溃,当我在 mediarecorder 上调用 prepare 时出现错误。

下面的布局 ///////////////////////////////////////// /////////////

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/camera_layout" android:layout_height="fill_parent"
    android:layout_width="fill_parent">
    <android.view.SurfaceView android:id="@+id/preview"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_alignParentTop="true">
    </android.view.SurfaceView>
    <Button android:id="@+id/start_video" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="Start Video">
    </Button>
    <Button android:id="@+id/stop_video" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="Stop Video"
        android:layout_toRightOf="@id/start_video">
    </Button>
</RelativeLayout>

代码如下 ///////////////////////////////////////// /////////////

public class start extends Activity 
{
    private SurfaceView preview;
    private SurfaceHolder previewHolder;
    private String locationName;
    private String filepath;
    private File video;

    public void onCreate(Bundle videocawk) {
        super.onCreate(videocawk);
        setContentView(R.layout.video_layout);
        setSurface();
        //locationName = getIntent().getStringExtra("locationName");
        locationName = "dan";
        filepath = getFilePath(locationName);
        try {
            MediaRecorder r = getMediaRecorder(filepath, previewHolder.getSurface());
            setButtonListeners(r);
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private String getFilePath(String locName) {
        String dir = Environment.getExternalStorageDirectory().getPath();
        String add = "/vext/";
        String name = locName + " -- 1";
        String total = dir + add + name;
        video = new File(total);
        return total;
    }

    private void setSurface() {
        preview = (SurfaceView) findViewById(R.id.preview);
        previewHolder = preview.getHolder();
        previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    private void setButtonListeners(final MediaRecorder r) {
        Button start = (Button) findViewById(R.id.start_video);
        Button end = (Button) findViewById(R.id.stop_video);

        start.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                startRecording(r);

            }
        });

        end.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                stopRecording(r);
                finish();

            }
        });

    }

    private void startRecording(MediaRecorder r) {
        r.start();
    }

    private void stopRecording(MediaRecorder r) {
        r.stop();
    }

    private MediaRecorder getMediaRecorder(String filepath, Surface s)
            throws IllegalStateException, IOException {
        MediaRecorder m_recorder = new MediaRecorder();
        m_recorder.setPreviewDisplay(s);
        m_recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
        m_recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        m_recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        m_recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
        m_recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
        m_recorder.setMaxDuration(20000); // length of video in MS
        m_recorder.setVideoSize(320, 240);
        m_recorder.setVideoFrameRate(15);
        m_recorder.setOutputFile(video.getPath());
        m_recorder.prepare();

        return m_recorder;
    }

}

我得到的错误是:

07-18 19:43:40.044: 错误/audio_input(987): 不支持的参数: x-pvmf/media-input-node/cap-config-interface;valtype=key_specific_value 07-18 19:43:40.044: 错误/audio_input(987): VerifyAndSetParameter 失败

07-18 19:43:40.044:错误/CameraInput(987):不支持的参数(x-pvmf/media-input-node/cap-config-interface;valtype=key_specific_value)

07-18 19:43:40.044: 错误/CameraInput(987): VerifiyAndSetParameter 在参数 #0 上失败

【问题讨论】:

    标签: android


    【解决方案1】:

    在 Android 的错误跟踪器上查看 issue 5063

    【讨论】:

      【解决方案2】:

      丹, 您的 logcat 在准备后是否包含以下内容?

      I/DEBUG   (20354): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
      I/DEBUG   (20354): Build fingerprint: 'vendor/inc/inc/inc:2.1-update1/ERE/2222:user/release-keys'
      I/DEBUG   (20354): pid: 20392, tid: 20392  >>> com.xyzzy.test <<<
      I/DEBUG   (20354): signal 11 (SIGSEGV), fault addr 00000078
      I/DEBUG   (20354):  r0 ffffe711  r1 ffffe700  r2 418b8528  r3 00000000
      I/DEBUG   (20354):  r4 ab309358  r5 0000aa90  r6 bee6d818  r7 4186bc6c
      I/DEBUG   (20354):  r8 bee6d830  r9 4186bc64  10 bee6d958  fp 4186bc60
      

      如果是这样,则此段错误可能与 MediaRecorder 状态机的计时问题有关。诀窍(显然)是确保在配置之后和准备之前有足够的(硬件特定的?)延迟。

      在此处查看讨论:

      http://code.google.com/p/android/issues/detail?id=5050

      【讨论】:

      • 附言。我忘了说,可能是不受支持的参数是红鲱鱼 - 尽管有一些人报告说录制成功。
      【解决方案3】:

      我可以确认http://code.google.com/p/android/issues/detail?id=5063 有正确的解决方案。确保将以下行添加到您的清单中:

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

      然后调用

      recorder = new MediaRecorder(); 
      recorder.reset();
      recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); 
      recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
      recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
      recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
      recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP); 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-08-15
        • 2015-08-13
        • 2017-04-19
        • 2021-05-14
        • 2022-01-02
        • 2011-02-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多