Hello everyone. Im trying out the new
Resources system with compose version 1.6.11 on Kotlin 2.0.0. I have added an audio file
composeResources/files/sound.mp3
. According to the post we're supposed to use
Res.getUri("files/sound.mp3")
to get a file path to read. Im new to Compose and especially Multiplatform and Im not sure how to read the file. I couldn't find any
File
class in
commonMain
so I created an
expect/actual fun playSound(path: String)
which I tried on Android by first reading the file with:
// path = "jar:file:/data/app/~~BCW32IAnb6EGfMOQvBQalQ==/<BUNDLE_ID>-di96yWV7A2Xl2lR01kWHBw==/base.apk!/composeResources/<PROJECT_NAME>.generated.resources/files/alarm.mp3"
actual fun playSound(path: String) {
File(path).readBytes() // Throws java.io.FileNotFoundException
}
Any help would be highly appreciated.
I just now tried with the
kotlinx-io-core
package with
SystemFileSystem.exists(Path(path))
which returns
false