对于录音权限问题 [英] Permission problems for sound recording

查看:620
本文介绍了对于录音权限问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个问题的设备上录制声音。在code我使用如果从Android开发人员网站(站点链接)和如下所示:

 公共无效onClickStart(视图V)抛出IllegalStateException异常,IOException异常{
        startRecord用于();
    }    公共无效onClickStop(视图V)抛出IllegalStateException异常,IOException异常{
        STO precord();
    }    私人无效startRecord用于()抛出IllegalStateException异常,IOException异常{
        记录=新MediaRecorder();
        recorder.setAudioSource(MediaRecorder.AudioSource.MIC); //好了,所以我说的音源是麦克风,它是Windows / Linux版麦克风模拟器?
        recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        recorder.setAudioEn codeR(MediaRecorder.AudioEn coder.AMR_NB);
        recorder.setOutputFile(/ SD卡/ test.3gpp);
        。录音机prepare();
        recorder.start();
    }    私人无效STO precord(){
        recorder.stop();
// recorder.release();
    }

随着主要布局2个按钮,它把两个停止和启动记录(理论上是)。

但是,从LogCat中我的设备(实在不能与试图在模拟器上被人打扰)我得到以下错误的尝试了这一点的时候:

 错误1:
ERROR / MediaRecorder(14541):启动名为无效状态:4
java.lang.IllegalStateException:无法执行活动的方法
java.lang.reflect.InvocationTargetException:产生的原因错误2:
java.io.FileNotFoundException:引起/sdcard/test.3gpp(权限被拒绝)

和我也有我的Manifest.xml文件设置以下权限:

 <使用许可权的android:NAME =android.permission.RECORD_AUDIO/>
<使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/>


愚蠢的错误在这里遗憾,它没有工作,因为我已经安装在我的笔记本电脑打电话,这样就不能真正达到SD卡。

I am having a couple of problems recording sound on a device. The code I am using if from the android dev site (Site Link) and is as follows:

    public void onClickStart(View v) throws IllegalStateException, IOException{
        startRecord();
    }

    public void onClickStop(View v) throws IllegalStateException, IOException{
        stopRecord();
    }

    private void startRecord() throws IllegalStateException, IOException{
        recorder = new MediaRecorder(); 
        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);  //ok so I say audio source is the microphone, is it windows/linux microphone on the emulator? 
        recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 
        recorder.setOutputFile("/sdcard/test.3gpp"); 
        recorder.prepare(); 
        recorder.start();  
    }

    private void stopRecord(){
        recorder.stop();
//      recorder.release();
    }

With 2 buttons in the main layout which it turn both stop and start the recording (in theory that is).

But from LogCat when trying this out on my device (really cant be bothered with trying on the emulator) I get the following errors:

Error 1:
ERROR/MediaRecorder(14541): start called in an invalid state: 4
java.lang.IllegalStateException: Could not execute method of the activity
Caused by: java.lang.reflect.InvocationTargetException

Error 2:
Caused by: java.io.FileNotFoundException: /sdcard/test.3gpp (Permission denied)

And I also have the following permissions set in my Manifest.xml file:

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

解决方案

Silly Error here sorry, it didn't work because I had the phone mounted on my laptop so it couldn't actually reach the sdcard.

这篇关于对于录音权限问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆