我試圖使用MediaRecorder類錄製視頻,我嘗試了很多例子,但所有例子都有同樣的問題,他們錄製了幾秒鐘,然後預覽停止了一些第二,這種情況發生了幾次之後,預覽被完全卡住,然後我得到下面的輸出:使用MediaRecorder錄製不起作用
04-05 15:53:59.257 26730-26730/? D/dalvikvm: Late-enabling CheckJNI
04-05 15:54:01.312 26730-26730/com.example.sition.videopoc D/libEGL: loaded /system/lib/egl/libEGL_MRVL.so
04-05 15:54:01.351 26730-26730/com.example.sition.videopoc D/libEGL: loaded /system/lib/egl/libGLESv1_CM_MRVL.so
04-05 15:54:01.359 26730-26730/com.example.sition.videopoc D/libEGL: loaded /system/lib/egl/libGLESv2_MRVL.so
04-05 15:54:01.375 26730-26730/com.example.sition.videopoc D/GC: <tid=26730> OES20 ===> GC Version : GC Ver SS_rls_pxa988_JB42_R1_RC2_GC13.16
04-05 15:54:01.421 26730-26730/com.example.sition.videopoc D/OpenGLRenderer: Enabling debug mode 0
04-05 15:54:01.437 26730-26730/com.example.sition.videopoc I/MediaRecorderJNI: prepare: surface=0x5ac59450 (identity=2933)
04-05 15:54:01.531 26730-26730/com.example.sition.videopoc D/v_gal: [tid=26730] gralloc_register_buffer: ===>Width = 800, Height = 480, surface = 0x5ac75c38
04-05 15:54:01.585 26730-26730/com.example.sition.videopoc D/v_gal: [tid=26730] gralloc_register_buffer: ===>Width = 800, Height = 480, surface = 0x5ac44360
04-05 15:54:02.789 26730-26730/com.example.sition.videopoc D/v_gal: [tid=26730] gralloc_unregister_buffer: ===>Width = 800, Height = 480, surface = 0x5ac75c38
04-05 15:54:02.789 26730-26730/com.example.sition.videopoc D/v_gal: [tid=26730] gralloc_unregister_buffer: ===>Width = 800, Height = 480, surface = 0x5ac44360
04-05 15:54:03.546 26730-26730/com.example.sition.videopoc W/IInputConnectionWrapper: showStatusIcon on inactive InputConnection
04-05 15:54:06.609 26730-26730/com.example.sition.videopoc I/MediaRecorderJNI: prepare: surface=0x5ac59450 (identity=2947)
04-05 15:54:06.656 26730-26730/com.example.sition.videopoc D/v_gal: [tid=26730] gralloc_register_buffer: ===>Width = 800, Height = 480, surface = 0x5ac75c38
04-05 15:54:06.765 26730-26730/com.example.sition.videopoc D/v_gal: [tid=26730] gralloc_register_buffer: ===>Width = 800, Height = 480, surface = 0x5ac44360
04-05 15:54:23.382 26730-26766/com.example.sition.videopoc W/Camera: Camera server died!
04-05 15:54:23.382 26730-26766/com.example.sition.videopoc W/IMediaDeathNotifier: media server died
04-05 15:54:25.382 26730-26730/com.example.sition.videopoc D/v_gal: [tid=26730] gralloc_unregister_buffer: ===>Width = 800, Height = 480, surface = 0x5ac75c38
04-05 15:54:25.382 26730-26730/com.example.sition.videopoc D/v_gal: [tid=26730] gralloc_unregister_buffer: ===>Width = 800, Height = 480, surface = 0x5ac44360
這是發生這種情況的活動:
public class MainActivity extends Activity implements View.OnClickListener, SurfaceHolder.Callback {
MediaRecorder recorder;
SurfaceHolder holder;
boolean recording = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
recorder = new MediaRecorder();
initRecorder();
setContentView(R.layout.activity_main);
SurfaceView cameraView = (SurfaceView) findViewById(R.id.cameraView);
holder = cameraView.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
cameraView.setClickable(true);
cameraView.setOnClickListener(this);
}
private void initRecorder() {
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
CamcorderProfile cpHigh = CamcorderProfile
.get(CamcorderProfile.QUALITY_HIGH);
recorder.setProfile(cpHigh);
recorder.setOutputFile("/sdcard/videocapture_example.mp4");
recorder.setMaxDuration(50000); // 50 seconds
recorder.setMaxFileSize(5000000); // Approximately 5 megabytes
}
private void prepareRecorder() {
recorder.setPreviewDisplay(holder.getSurface());
try {
recorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
finish();
} catch (IOException e) {
e.printStackTrace();
finish();
}
}
public void onClick(View v) {
if (recording) {
recorder.stop();
recording = false;
// Let's initRecorder so we can record again
initRecorder();
prepareRecorder();
} else {
recording = true;
recorder.start();
}
}
public void surfaceCreated(SurfaceHolder holder) {
prepareRecorder();
}
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
}
public void surfaceDestroyed(SurfaceHolder holder) {
if (recording) {
recorder.stop();
recording = false;
}
recorder.release();
finish();
}
}
這是佈局file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<SurfaceView
android:id="@+id/cameraView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
編輯:
我甚至無法打開此應用程序創建的文件(但他們不包含數據)。
'W /攝像頭:攝像頭服務器死'似乎是一個問題!這是什麼設備? – fadden
@fadden這是一個三星Galaxy S3迷你 –