Android:同时有两个媒体记录器实例

标签 android multithreading record mediarecorder

我可以同时运行 Android MediaRecorder 类的两个实例吗?例如

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();

调用第二个 start() 时出现此错误,我只想知道是因为已经调用了启动进程还是存在其他问题。第二个媒体记录器实例也被初始化并在单独的线程中使用。

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.

最佳答案

根据 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.

我不成功的尝试也一无所获。

关于Android:同时有两个媒体记录器实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16140703/

相关文章:

java - 使用 Mapstruct 作为 JOOQ 的 RecordMapper

MySQL:如何根据位置获取记录

android - OBJ vs 3DS - Android 3D 开发的最佳格式是什么

c - 定时器回调中的长过程

c# - 多线程错误 : There is already an open DataReader associated with this Connection which must be closed first

ios - dispatch_async 和异步请求的问题

android请求许可我不要求

android - 在 Android 中的同一 Activity 中使用两个 Volley 请求时如何修复空指针异常?

android (Service & PhoneStateListener) - 当应用程序被任务管理器、 killer 或内存不足杀死时,服务确实重启但不工作

java - 如何将xml扩充为 fragment 类?