Exemple #1
0
        void Init ()
        {
            mediaRouter = MediaRouter.GetInstance (this);

            mediaRouteSelector =
                new MediaRouteSelector.Builder ().AddControlCategory (MediaControlIntent.CategoryRemotePlayback) //CastMediaControlIntent.CategoryForCast (APP_ID))
                    .Build();
            mediaRouteButton.RouteSelector = mediaRouteSelector;

            myMediaRouterCallback = new MyMediaRouterCallback {
                OnRouteSelectedHandler = (router, route) => {

                    Console.WriteLine ("Route Selected: " + route.Name);

                    var device = CastDevice.GetFromBundle(route.Extras);

                    myCastListener = new MyCastListener();

                    var apiOptionsBuilder = new CastClass.CastOptions.Builder (
                        device,
                        myCastListener).SetVerboseLoggingEnabled (true);

                    googleApiClient = new GoogleApiClientBuilder(this)
                        .AddApi (CastClass.API, apiOptionsBuilder.Build())
                        .AddConnectionCallbacks (this)
                        .AddOnConnectionFailedListener (this)
                        .Build ();

                    googleApiClient.Connect();

                },
                OnRouteUnselectedHandler = (router, route) => {
                    Console.WriteLine ("Route Unselected: " + route.Name);
                },
                RouteCountChangedHandler = newCount => {
                    mediaRouteButton.Visibility = newCount > 0 ? ViewStates.Visible : ViewStates.Gone;
                }
            };

            mediaRouter.AddCallback(mediaRouteSelector, myMediaRouterCallback, MediaRouter.CallbackFlagRequestDiscovery);
        }
Exemple #2
0
        void Init()
        {
            mediaRouter = MediaRouter.GetInstance(this);

            mediaRouteSelector =
                new MediaRouteSelector.Builder().AddControlCategory(MediaControlIntent.CategoryRemotePlayback)   //CastMediaControlIntent.CategoryForCast (APP_ID))
                .Build();
            mediaRouteButton.RouteSelector = mediaRouteSelector;

            myMediaRouterCallback = new MyMediaRouterCallback {
                OnRouteSelectedHandler = (router, route) => {
                    Console.WriteLine("Route Selected: " + route.Name);

                    var device = CastDevice.GetFromBundle(route.Extras);

                    myCastListener = new MyCastListener();

                    var apiOptionsBuilder = new CastClass.CastOptions.Builder(
                        device,
                        myCastListener).SetVerboseLoggingEnabled(true);

                    googleApiClient = new GoogleApiClientBuilder(this)
                                      .AddApi(CastClass.API, apiOptionsBuilder.Build())
                                      .AddConnectionCallbacks(this)
                                      .AddOnConnectionFailedListener(this)
                                      .Build();

                    googleApiClient.Connect();
                },
                OnRouteUnselectedHandler = (router, route) => {
                    Console.WriteLine("Route Unselected: " + route.Name);
                },
                RouteCountChangedHandler = newCount => {
                    mediaRouteButton.Visibility = newCount > 0 ? ViewStates.Visible : ViewStates.Gone;
                }
            };

            mediaRouter.AddCallback(mediaRouteSelector, myMediaRouterCallback, MediaRouter.CallbackFlagRequestDiscovery);
        }