Support for playing Kotlin Multiplatform resources
@icbaker is already working on this.
Since May 28, 2024.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 955
- Avg merge
- 12d 14h
- Merged PRs (30d)
- 2
Description
Use case description
Main use case is about playing files inside APK with not only for example Uri:
Uri.parse(("file:///android_asset/music.mp3"))
But to be able to use files located in jar archive. For example Uri:
jar:file:/data/app/~~4hhLse7uFXE7V7sA==/com.example.composetest-jD6eQ3BeyvfQ==/base.apk!/composeResources/com.example.shared.resources/files/music.mp3
This approache can be used for multiplatform applications (e.i. multiplatform media players using AVPlayer on iOS and Exoplayer on Android with shared code) using Compose Multiplatform which will generated resources Uri for files inside common/shared directory. Mentioned directory "android_asset" is not accessible on iOS and generated resources Uri can't be used on Android. Media files needs to be duplicated to proper platform dependend directories.
More about Compose Multiplatform resources:
https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html
Proposed solution
Be able to use following code:
val mediaItem = MediaItem.Builder().setUri(Res.getUri("files/music.mp3")).build()
Alternatives considered
Only solution I can think of is using custom MediaSource and handling InputStream using method from Compose Multiplatform:
Res.readBytes("files/music.mp3")
with solution mentioned for example here (Exoplayer issue)
Similar issue is opened in Compose Multiplatform repository here and support from this side is not coming. The reasons are mentioned there.
Thank you for consideration!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.