Reputation: 122
I have a problem with cast SDK V3 for Android. I can't find and setup callback for MediaRouteButton, when it becomes visible (detects chromecast device). Thanks in advance!
Upvotes: 1
Views: 1790
Reputation: 55
I had exactly the same problem
I set it first : CastButtonFactory.setUpMediaRouteButton(nContext, nCastButton);
Then the addCastStateListener on CastContext;
The problem was there were not enough time for the CastButtonFactory to recognize the chromecast in my network. So the listener in the first place shoot me with "no device"
The fix was to add addSessionManagerListener on SessionManager and only on onSessionStarted or onSessionResumed to start setting the addCastStateListener on CastContext
Upvotes: 0
Reputation: 19034
You have a few options and you need to experiment to see which one fits your case:
You can use CastContext
to register a CastStateListener
. This listener provides information on the state of cast, one of them being "no cast device available", for example, so you can see when a cast device becomes available.
You can use DiscoveryManagerListener
which will inform you when the availability of cast device changes.
When you use CastButtonFactory
to add your cast button using setUpMediaRouteButton
, you get a MenuItem
back. You can then monitor the visibility of that menu item yourself.
Upvotes: 5