2014-02-21 123 views
2

我下載了這個示例http://developer.android.com/samples/MediaRecorder/index.html但它不起作用(在htc one v 4.0.3上測試過)。MediaRecorder示例不起作用

登錄:

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 
+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" /> 
+0

@sinigami:我的媒體錄像機的代碼片段錄製視頻如下:mediaRecorder = new MediaRecorder(); \t \t mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); \t \t mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); \t \t CamcorderProfile camcorderProfile_HQ = CamcorderProfile \t \t \t \t獲得(CamcorderProfile.QUALITY_HIGH); \t \t mediaRecorder.setProfile(camcorderProfile_HQ); \t \t mediaRecorder.setOutputFile(「/ sdcard/myvideo.mp4」); \t \t mediaRecorder.setMaxDuration(60000); //設置最大持續時間60秒。 \t \t mediaRecorder.setMaxFileSize(5000000); //設置最大文件大小5M –

+0

對於答案很好解釋+1,請張貼這些行作爲答案,它會更有用! –

+0

好的...我正在編輯我的答案,然後 –

1

這些行添加到您的AndroidManifest.xml:`

<uses-permission 
    android:name="android.permission.RECORD_AUDIO" /> 
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" />