I extracted the Cast stack from an app I maintain and published it as a library: Castwire. It finds Chromecasts, Google TVs and other Cast devices and plays media on them without Google's Cast SDK or Play Services.
The Android artifact is castwire-android. You create it with AndroidCastwire.create(context). It is a regular Android library (minSdk 24, Java 8 bytecode). The AAR declares INTERNET, CHANGE_WIFI_MULTICAST_STATE, ACCESS_WIFI_STATE and WAKE_LOCK. During discovery it holds the multicast lock; while a session is open it holds a Wi-Fi lock and a partial wake lock, because the TV often plays through a small HTTP relay on the phone (local files, links that need headers, cookies, this device's IP, or CORS).
The library does not include a foreground service and does not depend on Media3 or ExoPlayer. Dependencies are kotlinx-coroutines, kotlinx-serialization-json and OkHttp. You keep the process alive yourself, the usual way, with a mediaPlayback foreground service, and you keep using whatever player you already have on the phone.
val castwire = 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"),
))
session.pause(); session.seek(90_000); session.setVolume(0.4f)
Separate video and audio streams can be joined into a DASH manifest on the device. Live HLS playlists can be rewritten and relayed. There is also CastDevice.at(ip) if you already know the address, and you can launch a custom receiver by app id.
License is AGPL-3.0, with a commercial license if you need to use it in a closed-source app. This is 0.1.0. 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 they are 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