1

Important note - I am writing a JVM Desktop application.

I've tried KorAU libs but the documentation lacks examples it always fails with the following error for me:

fun main() {
  val file = File("path/that/exists.mp3")
  runBlocking {
    nativeSoundProvider.createSound(data=file.readBytes()).play()
  }
}
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 4608 out of bounds for length 4608

I've tried to second guess other methods but I ended up with an AudioFormatException

Some random IT boy
  • 7,569
  • 2
  • 21
  • 47
  • My guess is that `nativeSoundProvider.createSound()` is expecting a WAV while you are passing in an MP3. Try It looks like KorAU has utilities for reading and converting between different audio formats - try using one of those. – aSemy Mar 20 '23 at 12:04
  • I don't think so. [I checked the source code for the JVM nativeSoundProvider](https://github.com/korlibs/korge/blob/5e3056cfd0155fbbf6682d0ca4c42f5ec1e18fd9/korau/src/jvmMain/kotlin/com/soywiz/korau/sound/NativeSoundProviderJvm.kt) and it already provides the MP3Decoder within the `nativeAudioFormats` – Some random IT boy Mar 20 '23 at 12:15
  • Hmm okay, thanks for checking. Could you update your answer to include a full stacktrace? That might help track down what exactly the problem is. – aSemy Mar 20 '23 at 15:15

1 Answers1

0

According to the documentation, I tried this in a JVM desktop app in Windows and it worked.

suspend fun play() {
    val file = File("mymusic.mp3")
    if (file.exists())
            file.toVfs().readAudioStream().playAndWait()
}
YaMiN
  • 3,194
  • 2
  • 12
  • 36