开发者

Desperate Help Needed on media recorder

I'm trying to create a simple camcorder application using mediarecorder. The program keeps crashing and I get errors when I call prepare on the mediarecorder.

Layout Below ////////////////////////////////////////////////////////////////

<?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>

Code Below ////////////////////////////////////////////////////////////////

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.se开发者_运维技巧tAudioSource(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;
    }

}

The errors I get are:

07-18 19:43:40.044: ERROR/audio_input(987): unsupported parameter: x-pvmf/media-input-node/cap-config-interface;valtype=key_specific_value 07-18 19:43:40.044: ERROR/audio_input(987): VerifyAndSetParameter failed

07-18 19:43:40.044: ERROR/CameraInput(987): Unsupported parameter(x-pvmf/media-input-node/cap-config-interface;valtype=key_specific_value)

07-18 19:43:40.044: ERROR/CameraInput(987): VerifiyAndSetParameter failed on parameter #0


Check out issue 5063 on Android's bug tracker


Dan, does your logcat contain something like the following right after the prepare?

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

If so, this segfault may be related to timing issues with the MediaRecorder state machine. The trick (apparently) is to ensure that there is a sufficient (hardware specific?) delay after the configuration, and before the prepare.

See a discussion here:

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


I can confirm that http://code.google.com/p/android/issues/detail?id=5063 has the correct solution. Make sure to add the following lines to your manifest:

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

And then call

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜