今天使用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);
}
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!