I'm trying to play a sound in my Compose for Desktop project when pressing a button. My MP3 file is stored in the resources folder (./src/jvmMain/resources/beep.mp3).
I've been trying using the useResource
function as follows (inside onClick
parameter of a @Composable Button):
scope.launch {
useResource("beep.mp3") {
val clip = AudioSystem.getClip()
val audioInputStream = AudioSystem.getAudioInputStream(
it
)
clip.open(audioInputStream)
clip.start()
}
}
but I get an error: Exception in thread "AWT-EventQueue-0" java.io.IOException: mark/reset not supported. I got the same error if I don't use the scope
, which I define at the top level of my composable as:
val scope = rememberCoroutineScope()
Any help will be appreciated!