r/ComposeMultiplatform • u/lovespeedtest • 6d ago
Castwire: a JVM/Android Cast sender you can use from CMP Android and desktop targets (not iOS)
Castwire is a Google Cast sender for Kotlin and Java, without Google's SDK or Play Services. I am writing this up here only because the API is StateFlow, so it is usable from a Compose Multiplatform project's Android and desktop targets. It is not a CMP library and it does not run on iOS.
val devices by castwire.devices.collectAsState()
val status by session.status.collectAsState()
LaunchedEffect(Unit) { castwire.scan() }The core artifact is a plain JVM library (Java 8 bytecode, Android API 24+). AndroidCastwire.create(context) is the Android entry point and holds the multicast, Wi-Fi and wake locks. Discovery, the Cast v2 session, a local relay (for media the TV can't fetch itself) and building a DASH manifest from separate video and audio tracks are all in that JVM code. iPhone and iPad would still need AirPlay or something else.
val castwire = Castwire() // on Android: AndroidCastwire.create(context)
val tv = castwire.discover().first()
val session = castwire.connect(tv)
session.load(CastMedia(
CastSource.Url("https://example.com/movie.mp4", "video/mp4"),
MediaMetadata(title = "Movie"),
))License is AGPL-3.0, with a commercial license if you need to use it in a closed-source app.
The coordinates the build is set up for are io.github.biolend83:castwire:0.1.0 and io.github.biolend83:castwire-android:0.1.0, but 0.1.0 is not on Maven Central yet, so for now clone the repo.
https://github.com/biolend83/castwire
It came out of TubeHaus, a YouTube client I build: https://github.com/biolend83/tubehaus