我想在glsurfaceview android上录制。
private GLSurfaceView glview;
private Button start;
private Button stop;
private MediaRecorder mediaRecorder;
@Override
public void onClick(View v) {
if ( v == start) {
mediaRecorder = new MediaRecorder();
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mediaRecorder.setVideoSize(176, 144);
mediaRecorder.setVideoFrameRate(20);
mediaRecorder.setPreviewDisplay(glview.getHolder().getSurface());
mediaRecorder.setOutputFile("/sdcard/test001111.mp4");
try {
mediaRecorder.prepare();
mediaRecorder.start(); //occur exception
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
if (v == stop) {
if (mediaRecorder != null) {
mediaRecorder.stop();
mediaRecorder.release();
mediaRecorder = null;
}
}
}
}
我尝试搜索,但只在surfaceview示例上录制。
我想要GLSurfaceView
当我开始点击按钮时,发生异常。
和我的logcat
java.lang.RuntimeException: start failed.
at android.media.MediaRecorder.native_start(Native Method)
at android.media.MediaRecorder.start(MediaRecorder.java:726)
at com.example.unno.mywebrtc.MainActivity$TestVideoListener.onClick(MainActivity.java:134)
at android.view.View.performClick(View.java:4101)
at android.view.View$PerformClick.run(View.java:17080)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4863)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
如何在glsurfaceview上录制?
感谢。
@Update
清单
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
答案 0 :(得分:1)
检查清单文件中是否已给出适当的权限