0
votes

Is there a compatibility list for using music with libgdx? I've experience some difficulty with certain file extensions such as flac and wav. Flac does not seem to be supported on libgdx while wav files seem to be limited to 16 bit samplings. When attempting to play a flac music I receive the error:

Unknown file extension for music: aFlacFile.flac

The error is traced to the libgdx newMusic method:

public OpenALMusic newMusic (FileHandle file) {
    if (file == null) throw new IllegalArgumentException("file cannot be null.");
    Class<? extends OpenALMusic> musicClass = extensionToMusicClass.get(file.extension().toLowerCase());
    if (musicClass == null) throw new GdxRuntimeException("Unknown file extension for music: " + file);
    try {
        return musicClass.getConstructor(new Class[] {OpenALAudio.class, FileHandle.class}).newInstance(this, file);
    } catch (Exception ex) {
        throw new GdxRuntimeException("Error creating music " + musicClass.getName() + " for file: " + file, ex);
    }
}

As the error stated, *.flac does not seem to be a supported extension. The flac file I attempted to play had a bit depth of 16 bit, bit rate 588kps, and sample rate of 44 kHz. Also, some wav files would work while others did not:

Error creating music com.badlogic.gdx.backends.lwjgl.audio.Wav$Music for file: aWavFile.wav

...

GdxRuntimeException: Error reading WAV file: aWavFile.wav

...

GdxRuntimeException: WAV files must have 16 bits per sample: 24

Others have seem to come across this as well: Android Java LibGDX Music, Sound, as stated in the solutions comment and my exception thrown, the wav sampling requires a rate of 16 bit. Androids developer website, https://developer.android.com/guide/topics/media/media-formats, states that flac should be supported while wav is limited to 8/16 bit linear pcm. The Youtube tutorial by Gamefromscratch https://youtu.be/GN2KV4zQfEk?t=1712 mentions that libgdx audio may have less flexibility than standard utilities because of multi platform compatibility. Guess my question comes back to: does libgdx have a compatibility list for music extensions?

1

1 Answers

1
votes

I have tried the following formats:

1. mp3
2. ogg
3. Wav(16 bit)

Other formats could cause problems when you try to load it.