在 Android 上录制视频而不在屏幕上显示视频
我一直在尝试录制视频,但没有成功。我的代码可以编译,但当我尝试运行它时崩溃。有谁知道如何在不改变屏幕视图的情况下进行录制?谢谢。
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
recorder.setMaxDuration(15000); // 15 seconds
recorder.setMaxFileSize(5000000); // Approximately 5 megabytes
recorder.setOutputFile("/sdcard/xxxxx.mp4");
recorder.start();
I have been unsuccessfully trying to record video. My code compiles, but crashes when I try to run it. Does anyone know how I can record without changing the view on the screen? Thanks.
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
recorder.setMaxDuration(15000); // 15 seconds
recorder.setMaxFileSize(5000000); // Approximately 5 megabytes
recorder.setOutputFile("/sdcard/xxxxx.mp4");
recorder.start();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要指定一个有效的Surface:
recorder.setPreviewDisplay()。
然后您可以调用recorder.prepare()
,然后recorder.start()< /代码>。
对有效表面的需求非常烦人,这里有一个关于删除它的线程:
http://code.google.com/p/android/issues/detail?id=9570
例如,这将允许后台应用程序录制视频。
you need to specify a valid Surface:
recorder.setPreviewDisplay().
Then you can callrecorder.prepare()
, and only thenrecorder.start()
.The need for a valid surface is quit annoying, there's a thread about removing it here:
http://code.google.com/p/android/issues/detail?id=9570
That would for example allow background app to record video.