Android: Two instances of Media recorder at same time

自闭症网瘾萝莉.ら 提交于 2019-12-30 19:03:38

问题


Can i run two instances of Android MediaRecorder class at the same time? For example

public MediaRecorder mrec1 ;
public MediaRecorder mrec2 ;


mrec1.setCamera(mCamera);
mrec1.setPreviewDisplay(surfaceHolder.getSurface());
mrec1.setVideoSource(MediaRecorder.VideoSource.CAMERA)
.
.
.
.
mrec2.setAudioSource(MediaRecorder.AudioSource.MIC);
mrec2.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mrec2.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
.
.  
.
.
mrec1.prepare();
mrec2.prepare();
mrec1.start();
mrec2.start();

I get this error when second start() is called i just want to know is it because there is already a start process called or there is some other problem. Also the second media recorder instance is initialized and used in a separate thread.

04-22 11:08:45.869: E/MediaRecorder(7742): start failed: -2147483648
04-22 11:08:45.869: W/dalvikvm(7742): threadid=9: thread exiting with uncaught exception  (group=0x40018578)
04-22 11:08:45.869: E/AndroidRuntime(7742): FATAL EXCEPTION: Thread-10
04-22 11:08:45.869: E/AndroidRuntime(7742): java.lang.RuntimeException: start failed.

回答1:


according to documentation:

In addition to unnecessary resources (such as memory and instances of codecs) being held, failure to call this method immediately if a MediaRecorder object is no longer needed may also lead to continuous battery consumption for mobile devices, and recording failure for other applications if no multiple instances of the same codec are supported on a device. Even if multiple instances of the same codec are supported, some performance degradation may be expected when unnecessary multiple instances are used at the same time.

My unsuccessful attempts led to nothing either.



来源:https://stackoverflow.com/questions/16140703/android-two-instances-of-media-recorder-at-same-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!