简体   繁体   English

Android:同时有两个Media Recorder实例

[英]Android: Two instances of Media recorder at same time

Can i run two instances of Android MediaRecorder class at the same time? 我可以同时运行两个Android MediaRecorder类实例吗? 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. 当我调用第二个start()时,我只是想知道是因为已经有一个启动过程被调用,或者还有其他问题,所以我得到了这个错误。 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.

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. 除了保留不必要的资源(例如内存和编解码器实例)之外,如果不再需要MediaRecorder对象,则无法立即调用此方法也可能导致移动设备持续消耗电池,如果没有,则导致其他应用程序记录失败设备上支持同一编解码器的多个实例。 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. 我的不成功尝试也无济于事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM