catch recording error

pull/6/head
Ahmet Inan 2015-07-11 16:03:40 +02:00
rodzic 5286f176c1
commit 410c6c1f9c
1 zmienionych plików z 6 dodań i 2 usunięć

Wyświetl plik

@ -113,13 +113,17 @@ public class Decoder {
int bufferSizeInBytes = AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat);
if (bufferSizeInBytes <= 0)
throw new Exception("Unable to open audio with " + sampleRate + "Hz samplerate");
throw new Exception("Unable to open audio with " + sampleRate + "Hz samplerate.");
int bufferSizeInSamples = bufferSizeInBytes / 2;
int framesPerSecond = Math.max(1, sampleRate / bufferSizeInSamples);
audioBuffer = new short[framesPerSecond * bufferSizeInSamples];
audio = new AudioRecord(audioSource, sampleRate, channelConfig, audioFormat, audioBuffer.length * 2);
audio.startRecording();
if (audio.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING) {
audio.stop();
audio.release();
throw new Exception("Unable to start recording.\nMaybe another app is recording?");
}
int minValueBufferLength = 2 * sampleRate;
int valueBufferLength = Integer.highestOneBit(minValueBufferLength);
if (minValueBufferLength > valueBufferLength)