在 Android 中的 MediaRecorder 中包含音频
我在我的 Android 应用程序中集成了相机,可以通过移动相机录制视频并保存在 SD 卡中。它工作正常,但保存的 3gpp 文件没有附加音频。如果我添加音频配置,则相机无法打开,只会看到黑屏。这是我的代码:
if(camera == null) {
camera = Camera.open();
camera.unlock();
}
recorder.setCamera(camera);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
recorder.setOutputFile("/sdcard/adtvworld.3gpp");
recorder.setPreviewDisplay(holder.getSurface());
recorder.prepare();
I have integrated camera in my android app to record a video thr mobile camera and save in sdcard. it works fine, but the saved 3gpp file has no audio attached. If i add the configurations for audio the the camera does'nt open, just a black screen is seen. This is my code:
if(camera == null) {
camera = Camera.open();
camera.unlock();
}
recorder.setCamera(camera);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
recorder.setOutputFile("/sdcard/adtvworld.3gpp");
recorder.setPreviewDisplay(holder.getSurface());
recorder.prepare();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要按正确的顺序设置音频源和编码器。您收到的异常是 java.lang.IllegalStateException。尝试以下操作:
这段代码应该适合您。请随意将 AudioEncoder 更改为 AAC 以外的其他内容,尽管它对于低 kbps 来说是最有效的。
You need to set up audio source and encoder in a correct order. The exception you are getting is java.lang.IllegalStateException. Try following:
This piece of code should be working well for you. Feel free to change the AudioEncoder to something else than AAC, although it is the most efficient for low kbps.
也尝试设置音频源。
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
Try setting the audio source as well..
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);