kkostov / gadulka

A minimalistic player library for Kotlin Multiplatform. It targets Android, jvm and iOS, allowing consumers to play audio files
BSD 3-Clause "New" or "Revised" License
5 stars 0 forks source link

Any way to load from Compose Resource? #3

Open armond-avanes opened 4 days ago

armond-avanes commented 4 days ago

I'm looking for an API to be able to load audio files bundled with app. Or at least to be able to pass in a ByteArray of content to play. Looking into the docs and the source code, the only option was to play an online resource.

kkostov commented 4 days ago

Hi @armond-avanes, you're correct that there is no dedicated API for resources. Would it be a solution to treat it as a raw Resource e.g.:

  1. You place the audio file in the resources folder for raw files e.g. composeResources\files\sample.mp3

  2. Get the resource URI and pass it to the library:

// val player = GadulkaPlayer()
val uri = Res.getUri("files/sample.mp3")
player.play(uri)
armond-avanes commented 1 day ago

@kkostov That doesn't work because the underlying libraries (e.g. ExoPlayer on Android) are not designed to work with Compose Multiplatform resources.

kkostov commented 21 hours ago

I tested the approach above on Android, iOS and JVM and it seemed to work (not sure why, I think may be because of https://github.com/JetBrains/compose-multiplatform/pull/4965?), but perhaps it's not ideal for all situations.

You're definitely right that it makes sense to have a dedicated API using resources - it will make the interface of the library more accessible and easier to use so I will add it.