ExoPlayer
ExoPlayer copied to clipboard
Cast a MediaSource instead of a MediaItem
I'm looking into casting functionality and after looking into samples and the CastPlayer code source, it seems the cast player only allows media items as an entry point. My local player plays a MediaSource that merges two MediaItems (video mp4 and audio mp3). Is there a way to stream such a source with the cast player? Or I am limited to stream either one of them (video or audio)? Or maybe a way to convert the source somehow (although I doubt it)?
The snippet to create the media source
val videoSource = DefaultMediaSourceFactory(context).createMediaSource(MediaItem.fromUri(videoUrl))
val audioSource = DefaultMediaSourceFactory(context).createMediaSource(MediaItem.fromUri(audioUrl))
val sources = MergingMediaSource(videoSource, audioSource)
localPlayer = ExoPlayer.Builder(context).build()
castPlayer = CastPlayer(castContext)
localPlayer.setMediaSources(sources)
castPlayer.setMediaItems(sources) // <--- only media items accepted by CastPlayer
Thanks for your guidance!
I'm not aware that we can send something else than a single URI to the cast device (RemoteMediaClient) for playback. MergingMediaSource is a convenient feature of ExoPlayer but I don't think there is something like this available for a standard cast receiver application. This may (I'm totally not sure) be possible if you do your own receiver with a custom player like ShakaPlayer, but with RemoteMediaPlayer, the standard player and the standard API the Cast SDK offers I think this is not feasible.
Aside: I may be wrong and I would in this case be happy to hear about such an API of the Cast SDK. So if anyone in the audience can educate me about this I'm happy to learn and turn this issue into an enhancement.
Adding another comment: You may be able to turn your merging media source into a DASH or HLS manifest/playlist that references video and audio streams. Then you can create a DASH or HLS media item and pass it to the cast player's playlist API.
Thanks for those highlights, that's source for thoughts :) I'll look into it. Feel free to close the ticket if no one else jumps in anytime soon ;)