创建Android视频记录器时,setMaxDuration失败
|
我目前正在尝试在Android上创建一个非常简单的录像机,而不使用意图,而只是使用自定义应用程序。我的代码段如下
导入java.io.IOException;
导入android.app.Activity;
导入android.media.MediaRecorder;
导入android.net.NetworkInfo;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.SurfaceHolder;
导入android.view.SurfaceView;
公共类CameraActivity扩展Activity实现了SurfaceHolder.Callback {
公共枚举州{
未知,已连接,未连接
}
SurfaceView cameraView;
SurfaceHolder holder;
public boolean mListening;
public Object mState;
public NetworkInfo mNetworkInfo;
public boolean mSending;
boolean recording = false;
public static final String TAG = \"VIDEOCAPTURE\";
private MediaRecorder recorder;
protected void captureVideo() {
if (recording) {
recorder.stop();
// recorder.release();
recording = false;
Log.v(TAG, \"Recording Stopped\");
// Let\'s initRecorder so we can record again
initRecorder();
prepareRecorder();
} else {
recording = true;
recorder.start();
Log.v(TAG, \"Recording Started\");
}
}
private void initRecorder() {
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setOutputFile(\"/sdcard/videocapture_example.mp4\");
recorder.setMaxDuration(50000); // 50 seconds
recorder.setMaxFileSize(5000000);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
recorder = new MediaRecorder();
initRecorder();
setContentView(R.layout.main);
cameraView = (SurfaceView) this.findViewById(R.id.CameraView);
holder = cameraView.getHolder();
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
holder.addCallback(this);
}
private void prepareRecorder() {
recorder.setPreviewDisplay(holder.getSurface());
try {
recorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
finish();
} catch (IOException e) {
e.printStackTrace();
finish();
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
Log.v(TAG, \"surfaceCreated\");
prepareRecorder();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// camera.stopPreview();
// camera.release();
Log.v(TAG, \"surfaceDestroyed\");
if (recording) {
recorder.stop();
recording = false;
}
recorder.release();
finish();
}
}
但是,当我在模拟器中部署此代码时,在LogCat中出现了这样的错误。
java.lang.RuntimeException:无法启动活动ComponentInfo ...
java.lang.RuntimeException:setMaxDuration失败。
在android.media.MediaRecorder.setMaxDuration(本地方法)
我的代码有什么问题?
没有找到相关结果
已邀请:
1 个回复
草票