MediaRecorder示例不起作用

时间:2014-02-21 11:10:05

标签: android android-camera android-mediarecorder

我下载了此示例http://developer.android.com/samples/MediaRecorder/index.html,但它不起作用(在htc one v 4.0.3上测试过)。

日志:

com.example.android.mediarecorder D/dalvikvm﹕ Late-enabling CheckJNI
com.example.android.mediarecorder D/libEGL﹕ loaded /system/lib/egl/libGLES_android.so
com.example.android.mediarecorder D/libEGL﹕ loaded /system/lib/egl/libEGL_adreno200.so
com.example.android.mediarecorder D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_adreno200.so
com.example.android.mediarecorder D/libEGL﹕ loaded /system/lib/egl/libGLESv2_adreno200.so
com.example.android.mediarecorder I/Adreno200-EGLSUB﹕ <ConfigWindowMatch:2078>: Format RGBA_8888.
com.example.android.mediarecorder D/OpenGLRenderer﹕ Enabling debug mode 0
com.example.android.mediarecorder D/OpenGLRenderer﹕ has fontRender patch
com.example.android.mediarecorder V/MediaProfiles﹕ getCamcorderProfileParamByName: duration for camera 0, quality 1
com.example.android.mediarecorder V/MediaProfiles﹕ getCamcorderProfileParamByName: file.format for camera 0, quality 1
com.example.android.mediarecorder V/MediaProfiles﹕ getCamcorderProfileParamByName: vid.codec for camera 0, quality 1
com.example.android.mediarecorder V/MediaProfiles﹕ getCamcorderProfileParamByName: vid.bps for camera 0, quality 1
com.example.android.mediarecorder V/MediaProfiles﹕ getCamcorderProfileParamByName: vid.fps for camera 0, quality 1
com.example.android.mediarecorder V/MediaProfiles﹕ getCamcorderProfileParamByName: vid.width for camera 0, quality 1
com.example.android.mediarecorder V/MediaProfiles﹕ getCamcorderProfileParamByName: vid.height for camera 0, quality 1
com.example.android.mediarecorder V/MediaProfiles﹕ getCamcorderProfileParamByName: aud.codec for camera 0, quality 1
com.example.android.mediarecorder V/MediaProfiles﹕ getCamcorderProfileParamByName: aud.bps for camera 0, quality 1
com.example.android.mediarecorder V/MediaProfiles﹕ getCamcorderProfileParamByName: aud.hz for camera 0, quality 1
com.example.android.mediarecorder V/MediaProfiles﹕ getCamcorderProfileParamByName: aud.ch for camera 0, quality 1
com.example.android.mediarecorder V/MediaRecorderJNI﹕ setup
com.example.android.mediarecorder V/MediaRecorder﹕ constructor
com.example.android.mediarecorder V/MediaRecorder﹕ doCleanUp
com.example.android.mediarecorder V/MediaRecorder﹕ setListener
com.example.android.mediarecorder V/MediaRecorderJNI﹕ setMediaRecorder E: mr = mr
com.example.android.mediarecorder V/MediaRecorderJNI﹕ setMediaRecorder X
com.example.android.mediarecorder V/MediaRecorderJNI﹕ getMediaRecorder E
com.example.android.mediarecorder V/MediaRecorderJNI﹕ JNIMediaRecorderListener::setCamera
com.example.android.mediarecorder V/MediaRecorder﹕ setCamera(0x1375740,0x139eaf8)
com.example.android.mediarecorder V/MediaRecorderJNI﹕ process_media_recorder_call
com.example.android.mediarecorder V/MediaRecorderJNI﹕ setAudioSource(0)
com.example.android.mediarecorder V/MediaRecorderJNI﹕ getMediaRecorder E
com.example.android.mediarecorder V/MediaRecorder﹕ setAudioSource(0) E
com.example.android.mediarecorder V/MediaRecorder﹕ Call init() since the media recorder is not initialized yet
com.example.android.mediarecorder V/MediaRecorder﹕ init
com.example.android.mediarecorder V/MediaRecorder﹕ setAudioSource(0) X
com.example.android.mediarecorder V/MediaRecorderJNI﹕ process_media_recorder_call
com.example.android.mediarecorder V/MediaRecorderJNI﹕ setVideoSource(1)
com.example.android.mediarecorder V/MediaRecorderJNI﹕ getMediaRecorder E
com.example.android.mediarecorder V/MediaRecorder﹕ setVideoSource(1) E
com.example.android.mediarecorder V/MediaRecorder﹕ setVideoSource(1) X
com.example.android.mediarecorder V/MediaRecorderJNI﹕ process_media_recorder_call
com.example.android.mediarecorder V/MediaRecorderJNI﹕ setOutputFormat(2)
com.example.android.mediarecorder V/MediaRecorderJNI﹕ getMediaRecorder E
com.example.android.mediarecorder V/MediaRecorder﹕ setOutputFormat(2) E
com.example.android.mediarecorder V/MediaRecorderJNI﹕ process_media_recorder_call
com.example.android.mediarecorder V/MediaRecorderJNI﹕ setVideoFrameRate(30)
com.example.android.mediarecorder V/MediaRecorderJNI﹕ getMediaRecorder E
com.example.android.mediarecorder V/MediaRecorder﹕ setVideoFrameRate(30)
com.example.android.mediarecorder V/MediaRecorderJNI﹕ process_media_recorder_call
com.example.android.mediarecorder V/MediaRecorderJNI﹕ setVideoSize(640, 384)
com.example.android.mediarecorder V/MediaRecorderJNI﹕ getMediaRecorder E
com.example.android.mediarecorder V/MediaRecorder﹕ setVideoSize(640, 384)
com.example.android.mediarecorder V/MediaRecorderJNI﹕ process_media_recorder_call
com.example.android.mediarecorder V/MediaRecorderJNI﹕ setParameter()
com.example.android.mediarecorder V/MediaRecorderJNI﹕ getMediaRecorder E
com.example.android.mediarecorder V/MediaRecorder﹕ setParameters(video-param-encoding-bitrate=3000000)
com.example.android.mediarecorder V/MediaRecorderJNI﹕ process_media_recorder_call
com.example.android.mediarecorder V/MediaRecorderJNI﹕ setVideoEncoder(2)
com.example.android.mediarecorder V/MediaRecorderJNI﹕ getMediaRecorder E
com.example.android.mediarecorder V/MediaRecorder﹕ setVideoEncoder(2) E
com.example.android.mediarecorder V/MediaRecorder﹕ setVideoEncoder(2) X
com.example.android.mediarecorder V/MediaRecorderJNI﹕ process_media_recorder_call
com.example.android.mediarecorder V/MediaRecorderJNI﹕ setParameter()
com.example.android.mediarecorder V/MediaRecorderJNI﹕ getMediaRecorder E
com.example.android.mediarecorder V/MediaRecorder﹕ setParameters(audio-param-encoding-bitrate=12200)
com.example.android.mediarecorder V/MediaRecorderJNI﹕ process_media_recorder_call
com.example.android.mediarecorder V/MediaRecorderJNI﹕ setParameter()
com.example.android.mediarecorder V/MediaRecorderJNI﹕ getMediaRecorder E
com.example.android.mediarecorder V/MediaRecorder﹕ setParameters(audio-param-number-of-channels=1)
com.example.android.mediarecorder V/MediaRecorderJNI﹕ process_media_recorder_call
com.example.android.mediarecorder V/MediaRecorderJNI﹕ setParameter()
com.example.android.mediarecorder V/MediaRecorderJNI﹕ getMediaRecorder E
com.example.android.mediarecorder V/MediaRecorder﹕ setParameters(audio-param-sampling-rate=8000)
com.example.android.mediarecorder V/MediaRecorderJNI﹕ process_media_recorder_call
com.example.android.mediarecorder V/MediaRecorderJNI﹕ setAudioEncoder(1)
com.example.android.mediarecorder V/MediaRecorderJNI﹕ getMediaRecorder E
com.example.android.mediarecorder V/MediaRecorder﹕ setAudioEncoder(1) E
com.example.android.mediarecorder V/MediaRecorder﹕ setAudioEncoder(1) X
com.example.android.mediarecorder V/MediaRecorderJNI﹕ process_media_recorder_call
com.example.android.mediarecorder V/MediaRecorderJNI﹕ setOutputFile
com.example.android.mediarecorder V/MediaRecorderJNI﹕ getMediaRecorder E
com.example.android.mediarecorder V/MediaRecorder﹕ setOutputFile(55, 0, 0)
com.example.android.mediarecorder V/MediaRecorderJNI﹕ process_media_recorder_call
com.example.android.mediarecorder V/MediaRecorderJNI﹕ prepare
com.example.android.mediarecorder V/MediaRecorderJNI﹕ getMediaRecorder E
com.example.android.mediarecorder V/MediaRecorder﹕ prepare E
com.example.android.mediarecorder V/MediaRecorder﹕ prepare X
com.example.android.mediarecorder V/MediaRecorderJNI﹕ process_media_recorder_call
com.example.android.mediarecorder V/MediaRecorderJNI﹕ start
com.example.android.mediarecorder V/MediaRecorderJNI﹕ getMediaRecorder E
com.example.android.mediarecorder V/MediaRecorder﹕ start E
com.example.android.mediarecorder V/MediaRecorder﹕ start X
com.example.android.mediarecorder V/MediaRecorderJNI﹕ process_media_recorder_call
com.example.android.mediarecorder W/IMediaDeathNotifier﹕ media server died
com.example.android.mediarecorder W/Camera﹕ Camera server died!
com.example.android.mediarecorder W/Camera﹕ ICamera died
com.example.android.mediarecorder V/MediaRecorder﹕ died
com.example.android.mediarecorder V/MediaRecorder﹕ message received msg=1, ext1=100, ext2=0
com.example.android.mediarecorder V/MediaRecorder﹕ callback application
com.example.android.mediarecorder V/MediaRecorderJNI﹕ JNIMediaRecorderListener::notify
com.example.android.mediarecorder V/MediaRecorderJNI﹕ notify msgType 0x1, ext1 0x64
com.example.android.mediarecorder V/MediaRecorder﹕ back from callback
com.example.android.mediarecorder E/Camera﹕ Error 100

3 个答案:

答案 0 :(得分:3)

您是否在代码中添加了这一行?

MediaRecorder mediaRecorder = new MediaRecorder(); 
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); 
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
 CamcorderProfile camcorderProfile_HQ = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
mediaRecorder.setProfile(camcorderProfile_HQ);
 mediaRecorder.setOutputFile("/sdcard/myvideo.mp4");
 mediaRecorder.setMaxDuration(60000); // Set max duration 60 sec. 
mediaRecorder.setMaxFileSize(5000000); // Set max file size 5M

还需要权限:

<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

答案 1 :(得分:1)

将这些行添加到AndroidManifest.xml:`

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

答案 2 :(得分:0)

这个问题似乎是android清单中没有提供的权限。我们需要确保清单上的权限

在您的清单中使用以下权限

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />

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

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