Hi all,
I’m trying to load an audio file and then get the audio data as an array using LibGDX, but it is not able to load the audio file. I’m currently using a wav file (I’d like to be able to use mp3’s as well) which is located in the Android assets folder where I have other files for creating text, buttons, etc. and these all work, so it is only the wav file that isn’t loading.
The wav file format is PCM, 44.1kHz, 16bit, mono, little endian.
Here is all the code I have added so far to see if it would pass the wav file to the AudioInputStream without crashing:
try {
FileHandle fileHandle = Gdx.files.internal("click.wav");
InputStream inputStream = fileHandle.read();
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(inputStream);
}
catch (UnsupportedAudioFileException e) { e.printStackTrace(); }
catch (IOException e) { e.printStackTrace(); }
I’ve debugged the program and after the line that should create the FileHandle, the handle’s status is “null”. The Gdx.files.internal() method is what I used to load my files for the graphics and they are working.
When I run the program it crashes on the line:
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(inputStream);
Here is the error message I get:
java.io.IOException: mark/reset not supported
at java.io.InputStream.reset(Unknown Source)
at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unknown Source)
at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
at com.tekker.audioanimation.SoundFile.readAudioFile(SoundFile.java:61)
at com.tekker.audioanimation.SoundFile.<init>(SoundFile.java:33)
at com.tekker.audioanimation.Event.<init>(Event.java:30)
at com.tekker.audioanimation.AudioAnimation.initArrays(AudioAnimation.java:82)
at com.tekker.audioanimation.AudioAnimation.create(AudioAnimation.java:67)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
Any ideas what I’m doing wrong? Thanks!