Michal Havryluk
12/27/2023, 3:58 PMapplicationContext.javaClass.classLoader?.getResource("music.mp3")
This will get something like this as URL:
jar:file:/data/app/~~703PFoktDXUKZn5lPAVPA==/com.example.test-AtrtrkqGf82Y2vOReZF9Ew==/base.apk!/music.mp3
But I have problem with creating Android Uri which is needed for ExoPlayer and its MediaItem:
MediaItem.Builder().setUri(uri).build()
This will throw:
<http://sun.net|sun.net>.<http://www.protocol.jar.JarURLConnection|www.protocol.jar.JarURLConnection> cannot be cast to java.net.HttpURLConnection
Is there any solition other than copying the resource to the assets directory for Android?
It will be then accessible using:
Uri.parse(("file:///android_asset/music.mp3"))
Thankselectrolobzik
12/27/2023, 5:10 PMMichal Havryluk
12/27/2023, 6:00 PMtasks.register<Copy>("copyiOSTestResources") {
from("src/commonTest/resources")
into("build/bin/iosX64/debugTest/resources")
}
tasks.findByName("iosX64Test")!!.dependsOn("copyiOSTestResources")
It's taken from:
https://developer.squareup.com/blog/kotlin-multiplatform-shared-test-resources/
Also worth mentioning that article listed above from Jetbrains website has also part about placing resources in platform specific folders if shared resource folder is not an option. Shared resource folder is working so far good for me (don't counting that Uri problem).electrolobzik
12/27/2023, 6:10 PMMichal Havryluk
12/27/2023, 6:19 PMtasks.register("PreCommitMessage", Copy::class) {
from(file("${rootProject.rootDir}/commit-msg"))
into(File(rootProject.rootDir, ".git/hooks"))
}
What are you using for accessing that shared resources folder on iOS? I'm using:
NSBundle.mainBundle.resourcePath + "/compose-resources/" + asset // asset is name of the resource
electrolobzik
12/27/2023, 6:27 PMMichal Havryluk
12/27/2023, 6:33 PMelectrolobzik
12/27/2023, 6:37 PMMichal Havryluk
05/28/2024, 7:42 PM