在服务中使用 mediaReorder。音频正常 - 视频崩溃
if (audio == true & video == true)
{
Camera camera = Camera.open();
camera.unlock();
recorder.setCamera(camera);
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setVideoSize(640,480);
recorder.setVideoFrameRate(15);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
recorder.setAudioEncoder((MediaRecorder.AudioEncoder.DEFAULT));
recorder.setPreviewDisplay(null);
filesuffix = ".mp4";
filename = formatteddate.concat(filesuffix);
recorder.setOutputFile(path.concat(filename));
recorder.setAudioEncodingBitRate(96000);
recorder.setAudioSamplingRate(96000);
try {recorder.prepare();}
catch (IllegalStateException e) {e.printStackTrace();}
catch (IOException e) {e.printStackTrace();}
recorder.start();
};
它创建文件,然后服务崩溃。
logcat 报告失败:
Caused by: java.lang.IllegalStateException
at android.media.MediaRecorder.start(Native Method)
at [ ].PPS.onCreate(PPS.java:144)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3033)
仅录制音频时,效果非常好。任何建议表示赞赏。
if (audio == true & video == true)
{
Camera camera = Camera.open();
camera.unlock();
recorder.setCamera(camera);
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setVideoSize(640,480);
recorder.setVideoFrameRate(15);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
recorder.setAudioEncoder((MediaRecorder.AudioEncoder.DEFAULT));
recorder.setPreviewDisplay(null);
filesuffix = ".mp4";
filename = formatteddate.concat(filesuffix);
recorder.setOutputFile(path.concat(filename));
recorder.setAudioEncodingBitRate(96000);
recorder.setAudioSamplingRate(96000);
try {recorder.prepare();}
catch (IllegalStateException e) {e.printStackTrace();}
catch (IOException e) {e.printStackTrace();}
recorder.start();
};
it creates the file, then the service crashes.
logcat reports fail on:
Caused by: java.lang.IllegalStateException
at android.media.MediaRecorder.start(Native Method)
at [ ].PPS.onCreate(PPS.java:144)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3033)
when recording only audio, works excellent. any suggestions are appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论