Which is the route to acces a file stored in `comm...
# multiplatform
p
Which is the route to acces a file stored in
commonMain/composeResouces/files/audio.wav
? I tryed with
File("files/audio.wav")
and gave me
.FileNotFoundException
g
Have you tried to use this?
p
No, that doesn't fit my needs
I already watched that guide, and they use another logic
Res.readBytes("files/myDir/someFile.bin")
on the other hand, I followed that path style and because of that I used "files/audio.wav", but with no result
m
For a file located in
commonMain/composeResouces/files/audio.wav
the correct way to read it is
Res.readBytes("files/audio.wav")
. I read a config file that way in my projects.
g
I don't think that you can use
File
API to access you resources. You're assuming that the files are stored "near" your executable, but it is not true and heavily dependent on the platform you're running on.
Why do you need to handle it as a file?
p
but I need a File, because I need to pass it to my sound manager:
Copy code
val audioInputStream = AudioSystem.getAudioInputStream(File(sound.path))
val clip: Clip = AudioSystem.getClip()
clip.open(audioInputStream)
clip.start()
this is also happening in a sound effects manager class, which is a singleton shared between my app, not a composable
I need to receive the File to pass it to
AudioSystem.getAudioInputStream
m
This is not the only way. You could also read the bytes and wrap them in an InputStream and then initialize the AudioStream with that.
p
it seems to be like killing flyes with tanks
also that whould require a coroutine scope (is a suspend function)
are you sure there is no other way to read a .wav file? maybe placing it in another folder?
m
Yes, but that’s a good idea anyway.
p
can you share how to do it please?
m
No, because I go to bed now đŸ˜´.
p
good night Michael!
well I'm stuck with this, if someone can give me any clue about how to achieve this, I'll be great