【发布时间】:2018-03-16 22:36:29
【问题描述】:
我正在尝试使用 mediarecorder 创建一个简单的摄像机应用程序。程序不断崩溃,当我在 mediarecorder 上调用 prepare 时出现错误。
下面的布局 ///////////////////////////////////////// /////////////
<?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>
代码如下 ///////////////////////////////////////// /////////////
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.setAudioSource(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;
}
}
我得到的错误是:
07-18 19:43:40.044: 错误/audio_input(987): 不支持的参数: x-pvmf/media-input-node/cap-config-interface;valtype=key_specific_value 07-18 19:43:40.044: 错误/audio_input(987): VerifyAndSetParameter 失败
07-18 19:43:40.044:错误/CameraInput(987):不支持的参数(x-pvmf/media-input-node/cap-config-interface;valtype=key_specific_value)
07-18 19:43:40.044: 错误/CameraInput(987): VerifiyAndSetParameter 在参数 #0 上失败
【问题讨论】:
标签: android