MediaRecorder start fail -2147483648

醉酒当歌 提交于 2019-11-29 15:47:19

It's possible that the device you're running your app on either doesn't support voice call recording at all, or that it doesn't like one or more of the parameters you've tried to set.
For example, you could try using an 8000 Hz sample rate instead of 44100 Hz (44100 Hz makes no sense for AMR-NB anyway) and getting rid of the call to setAudioEncodingBitRate altogether.

Another potential problem with your code is that you've got the MediaRecorder instance in your BroadcastReceiver object, and haven't declared it static. Here's what the Android documentation has to say about BroadcastReceivers:

A BroadcastReceiver object is only valid for the duration of the call to onReceive(Context, Intent). Once your code returns from this function, the system considers the object to be finished and no longer active.

In other words, the MediaRecorder instance that you expect to be there when you get a broadcast containing EXTRA_STATE_IDLE might actually not exist anymore since you're within a different BroadcastReceiver instance than the one that created the MediaRecorder.

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