Cast Android TV Receiver - Correct implementation with Media3
What is the current best approach to implement the Cast Android TV Receiver SDK with Media3?
- I did not find any useful information on this to date.
- The Media3 Demo project directory contains only Cast Sender example.
- ExoPlayer project related references Cast docs, CastAndroidTvReceiver example, Marc Medium post are all outdated, deprecated and they no longer exist in Media3 (ie
MediaSessionConnector). - Based on findings from
CastPlayersource code, it always usesremoteMediaClient.queueLoadmethod, which requires a specific approach on Receiver side.
I have a very basic implementation done at the moment, but I don't know exactly when and what to broadcast with the MediaStatus differently from the official example mentioned above.
For example (int) currentTimeline.getPeriod(mediaItemIndex, period).uid in CastPlayer seekTo method returns (after disconnection and after new connection) wrong value (exceeding the queue size). But this works fine with the Default Web Receiver App, so from this I conclude that I am missing something to properly integrate on the Receiver side.
Is there an official demo planned, like is there the one for Cast Sender?
Like you state, the CastPlayer uses the RemoteMediaClient to prepare the player with a queue and send playback commands. These messages are then sent by the Cast SDK to the receiver SDK on the cast device.
In the manifest of the cast demo app is a cast options provider registered. It uses DefaultCastoptionsProvider provided by the library that declares the app id to be started.
You can do your own receiver/options provider and change that ID to your app ID.
I don't know much about the receiver side API to be honest. The web receiver SDK gives you a <cast-media-player> element and API components like a context, a PlayerManager and friends. Your app basically displays that HTML-element and the playback commands sent by CastPlayer through RemoteMediaClient are received and applied by the SDK on the receiver end. The rest around that is your HTML/JS app.
From what I know, CastPlayer works with the default receiver, a styled receiver or such a custom receiver that uses the Cast web SDK.
For more information on how to implement such a receiver we can't help you here in much more detail I'm afraid. The links above should be a starting point.
First thank you for your attention Marc,
I know you get a lot of questions every day and I'm sorry, I probably didn't describe my question well enough. I'm working on integration Cast Android TV Receiver App (not the Web Receiver App):
And as I mentioned above, I have already completed the basic integration and it partially works, but I have already spent a lot of time on some edge cases and I still cannot solve some of them.
That's why I asked if you are planning any official demo / integration support, like you have for the Cast Sender part (the CastPlayer)?
Btw: The link to your medium post with the old MediaSessionConnector I mentioned because it is listed as a reference link in the code lab for ATV app integration at the very bottom of the page 4 🙂
Yeah, sorry I'm not familiar with this. That's an app published by Cast folks. We weren't involved.
I can just point to this page that references a code lab and a sample app, but you are probably better informed about these resources than I am.
We don't have plans to provide a Android TV receiver app any time soon. Sorry for not having a better answer.
@pflammertsma or @AquilesCanta may have some thoughts.
@marcbaechinger @AquilesCanta @pflammertsma hello guys, any update regarding this? @TomasValenta were you able to figure it out on your own?
Sorry for the late reply! We’ve decided to postpone this feature for now and continue using the Default Web Receiver App.
Thanks! I'm closing mostly because I can't really help. The cast team would need to help here I think.
Apologies, I hadn't seen this before.
Media3, through the cast extension, only supports sender-side integration as of today. Which means this is not really the right place to ask about CastConnect / AndroidTV native receiver. I think the right place to file this would be https://issuetracker.google.com/issues/new?component=190205&template=814901.
I have some plans to work on CastConnect integration functionality in the context of the Cast extension in media3, but I cannot give you any specific timelines just yet, as we are still working on improving the sender side functinoality. Hopefully you've had a chance to try the latest Cast extension changes?
So for the time being, I think the link that Marc provided above is the right place https://developers.google.com/cast/docs/android_tv_receiver/core_features. Otherwise, hopefully, we'll be able to give you a better answer in 2026, so that you can launch your native Android app when casting to an Android TV.