当前位置: 移动技术网 > IT编程>移动开发>Android > Android解决异常: startRecording() called on an uninitialized AudioRecord.

Android解决异常: startRecording() called on an uninitialized AudioRecord.

2019年04月21日  | 移动技术网IT编程  | 我要评论

花丛任逍遥,我爱歌唱伴奏,皮革切割机

今天使用audiorecord进行录音操作时候,报了下面的异常。

e/androidruntime(22775): java.lang.illegalstateexception: startrecording() called on an uninitialized audiorecord.

解决办法:
1.看权限是否添加;


我的权限添加了还是报错。网上查找资料发现:出现上面问题的原因是录音的硬件资源被申请了,但是没有释放,然后你再次申请资源,导致初始化失败。这里需要注意的是不仅仅需要调用release()方法。还需要把audiorecord对象置为null,否则还是释放失败。下面是android 开发网上面的一个对于audiorecord的释放说明。

releases the native audiorecord resources. the object can no longer be used and the reference should be set to null after a call to release()。

所以要加个判断:

            if(record == null){
                record = new audiorecord(mediarecorder.audiosource.mic, msamplerate, mchannelconfig, maudioencoding, mbuffersize * 5);
            }

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网