1

We deployed our app on amazon and sometimes we are getting null when retrieving the audio output sample rate from the audio manager on a kindle.

Our code is (more or less as follows:

AudioManager audioService = (AudioManager) myApp.getSystemService(Context.AUDIO_SERVICE)

int sampleRate = Integer.parseInt(audioService.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE));

Our app sometimes crashes when parsing - complaining about NumberFormatException originating from a null value it got.

Are there some known issues with kindle or amazon devices in this area ?

drorsun
  • 881
  • 1
  • 8
  • 22

3 Answers3

1

I had this too on KITKAT API 19(LG L65 rooted) and use permission.RECORD_AUDIO . But these constants add API 17! But I get null!

getProperty("PROPERTY_OUTPUT_FRAMES_PER_BUFFER");
getProperty("PROPERTY_OUTPUT_SAMPLE_RATE");

return null.

A string representing the associated value for that property key, or null if there is no value for that key.

Usually if get null you must use(most popular android values):

FRAMES_PER_BUFFER = 256 
DEFAULT_SAMPLING_RATE = 44100

Example there https://github.com/ReadyTalk/webrtc/blob/master/webrtc/modules/audio_device/android/java/src/org/webrtc/voiceengine/AudioManagerAndroid.java

Fortran
  • 2,218
  • 2
  • 27
  • 33
0

Currently Amazon Kindles support Android 4.1 or higher.

According to the Android Docs, PROPERTY_OUTPUT_SAMPLE_RATE was added in Android API Level 17, aka Android 4.2.

It seems like PROPERTY_OUTPUT_SAMPLE_RATE may not be supported in Amazon Kindles because it may be running an outdated version of Android (4.1 < 4.2).

Try updating your Kindles' Android!

Happypig375
  • 1,022
  • 1
  • 12
  • 32
0

THE "solution":

val AudioManager.outputFramesPerBuffer: Int
    get() = getProperty(PROPERTY_OUTPUT_FRAMES_PER_BUFFER)
        ?.asInt().takeUnless { it == 0 } ?: 256

val AudioManager.outputSampleRate: Int
    get() = getProperty(PROPERTY_OUTPUT_SAMPLE_RATE)
        ?.asInt().takeUnless { it == 0 } ?: 44100
Renetik
  • 5,887
  • 1
  • 47
  • 66