首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android2.2和2.3录音失败.解决方法

2012-04-01 
android2.2和2.3录音失败.以下代码在2.1中没有问题,Java codeprivate void startRecord(Context context,

android2.2和2.3录音失败.
以下代码在2.1中没有问题,

Java code
private void startRecord(Context context, Intent intent){        String path = intent.getStringExtra(AndrecorderContactHelper.FILEPATH);        recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);        //        String _type = AndrecorderConfiguration.getConfiguration(context).getRecordType();        int format = OutputFormat.DEFAULT;        if (_type.equalsIgnoreCase("amr"))            format = OutputFormat.RAW_AMR;        else if (_type.equalsIgnoreCase("3gp"))            format = OutputFormat.THREE_GPP;        else if (_type.equalsIgnoreCase("mp4"))            format = OutputFormat.MPEG_4;        recorder.setOutputFormat(format);        recorder.setAudioEncoder(AAC);        recorder.setOutputFile(path);        try {            recorder.prepare();            recorder.start();        } catch (IllegalStateException e) {                        e.printStackTrace();        } catch (IOException e) {                        e.printStackTrace();        }                //        Log.i("whut", "开始录音");        recording = true;    }


但是在2.3中recorder.start()处就会出错.
logcat窗口提示 start failed: -22
在网上照了一些资料也没有看到解决的方案.
在此求助了.

[解决办法]
有在AndroidManifest.xml文件里添加录音权限吗?
[解决办法]
得看看在hal层有没有call到,有没有正确调用到录音设备通路、参数等。

热点排行