I think this issue is more related with Compose De...
# compose-desktop
p
I think this issue is more related with Compose Desktop than with multiplatform itself. Has anyone achieved getting files from
commonMain/composeResouces/files
using
Res.getUri()
? I'm trying to use
Res.getUri
to play a wav file, and I got
filenotfoundexception
when passing it to AudioSystem.getAudioInputStream:
Copy code
val uri = Res.getUri("files/frog.wav")
val audioInputStream = AudioSystem.getAudioInputStream(File(uri))
According to documentation, If you want to process multiplatform resources using other libraries included in your project, you can pass platform-specific file paths to these other APIs. To get a platform-specific path, call the
Res.getUri()
function with the project path to the resource
The route in which is located the file is inside a .jar, maybe that is the problem, but the documentation doesn't tell how to solve it.
Solved, It was necessary to cut all the uri route until the end of the .jar, so I made a substring until
!/
Also it was necessary to add buffer for mark/reset support. Finally the working code is as follows:
Copy code
val uri = Res.getUri(sound.path)
val resourcePath = uri.substringAfter("!/") // getting the route inside the jar
val resourceStream: InputStream? = javaClass.getResourceAsStream("/$resourcePath")
    
resourceStream?.let {
    val bufferedIn: InputStream = BufferedInputStream(resourceStream) // adding buffer for mark/reset support
    val audioInputStream = AudioSystem.getAudioInputStream(bufferedIn)
    val clip: Clip = AudioSystem.getClip()
    clip.open(audioInputStream)
    clip.start()
}