1

I tried to make a tuner for my guitar in android app. For this I've to used the library AudioRecord.java, but at the compiation an error appears:

07-03 13:48:49.041 2391-2426/? E/AudioRecord: AudioFlinger could not create record track, status: -1
07-03 13:48:49.044 2391-2426/? E/AudioRecord-JNI: Error  creating AudioRecord instance: initialization check failed with status -1.
07-03 13:48:49.044 2391-2426/? E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.

      --------- beginning of crash
07-03 13:48:49.046 2391-2426/? E/AndroidRuntime: FATAL EXCEPTION: Thread-5
    Process: com.example.gaetan.tuner, PID: 2391
    java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord.
        at android.media.AudioRecord.startRecording(AudioRecord.java:976)
        at com.example.gaetan.tuner.audio.CaptureThread.run(CaptureThread.java:34)

And in AudioRecord.java I can see

import android.os.ServiceManager; cannot be resolved 

What can I do to change that?

mortalis
  • 2,060
  • 24
  • 34
gaetan0221
  • 21
  • 2
  • Looks like a RuntimeException, not a compilation error – OneCricketeer Jul 03 '17 at 14:19
  • Please show your code! – Jack Dalton Jul 03 '17 at 15:00
  • The missing import is just and IDE issue – ApriOri Jul 03 '17 at 15:25
  • I want want to used this code https://github.com/wespay/pTune and in CaptureThread.java we used the library AudioRecord https://github.com/android/platform_frameworks_base/blob/master/media/java/android/media/AudioRecord.java the import at line 29 in AudioRecord.java can't be find and make error at line 277(GetCapturPreset()) or 279(getTags()) for example can't be find – gaetan0221 Jul 04 '17 at 20:02

1 Answers1

0

The issue is likley to do with supported sample rates. The following code will give you a predicate for checking if your desired sample rate is supported.

        int sampleRate = 44100;
        int bufferSize = AudioRecord.getMinBufferSize(44100, AudioFormat.CHANNEL_CONFIGURATION_DEFAULT, AudioFormat.ENCODING_PCM_16BIT);

        if (bufferSize > 0) {
            //the sample rate is supported so create your AudioRecord
        } else {
            // sample size is not supported
        }

For a more advanced version featuring that supports multiple sample rates see the answer given here

Jack Dalton
  • 3,536
  • 5
  • 23
  • 40