Libgdx AndroidAudio录音机

时间:2016-12-01 15:58:30

标签: android libgdx audio-recording

尝试初始化AndroidAudioRecorder时,我的应用程序因此错误而崩溃:

 Unable to initialize AudioRecorder. Do you have the RECORD_AUDIO permission

AndroidManifest包含此行

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

这是Recorder类

public class AndroidAudioRecorder implements AudioRecorder {

private AudioRecord recorder;

public AndroidAudioRecorder (int samplingRate, boolean isMono) {

    int channelConfig = isMono ? AudioFormat.CHANNEL_IN_MONO : AudioFormat.CHANNEL_IN_STEREO;
    int minBufferSize = AudioRecord.getMinBufferSize(samplingRate, channelConfig, AudioFormat.ENCODING_PCM_16BIT);

    recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, samplingRate, channelConfig, AudioFormat.ENCODING_PCM_16BIT,
            minBufferSize);

    if (recorder.getState() != AudioRecord.STATE_INITIALIZED)
        recorder.startRecording();
}


@Override
public void dispose () {
    recorder.stop();
    recorder.release();
}

@Override
public void read (short[] samples, int offset, int numSamples) {
    int read = 0;
    while (read != numSamples) {
        read += recorder.read(samples, offset + read, numSamples - read);
    }
}

}

这就是它被初始化的地方

public class AndroidLauncher extends AndroidApplication {

private final int screenWidth = 480;
private final int screenHeight = 800;

@Override
protected void onCreate (Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();

    AudioRecorder r = new AndroidAudioRecorder(44100, true);
    initialize(new MyApp(screenWidth, screenHeight, r), config);
}

}

0 个答案:

没有答案