Search code examples
javaandroidgoogle-castchromecast

cast button not showing up on Demo


I am running the demo from https://github.com/googlecast/CastVideos-android .

It is dependent the library located here https://github.com/googlecast/CastCompanionLibrary-android

The project is set up with all the necessary libraries and required jar.

The project compiles and runs no problem except that the chromecast button does not show up in the actionBar.

The button shows up if I modify onCreate with the following :

mSelector = new MediaRouteSelector.Builder()
      .addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO)
      .addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO)
      .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
      .addControlCategory(CastMediaControlIntent.categoryForCast(getResources().getString(R.string.app_id))).build();

and modify onCreateOptionsMenu with the following :

 @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        getMenuInflater().inflate(R.menu.main, menu);

      //mediaRouteMenuItem = mCastManager.addMediaRouterButton(menu, R.id.media_route_menu_item);
      //Attach the MediaRouteSelector to the menu item

        //MenuItem 
        mediaRouteMenuItem = menu.findItem(R.id.media_route_menu_item);
        MediaRouteActionProvider mediaRouteActionProvider = (MediaRouteActionProvider)MenuItemCompat.getActionProvider(mediaRouteMenuItem);
        mediaRouteActionProvider.setRouteSelector(mSelector);
        return true;
    }

If I simply leave onCreateOptionsMenu as it was out of the box, then it does not work.

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        getMenuInflater().inflate(R.menu.main, menu);

        mediaRouteMenuItem = mCastManager.addMediaRouterButton(menu, R.id.media_route_menu_item);        
        return true;
    }

Any ideas as to why this is?


Solution

  • Your device is probably not whitelisted for your app. You might want to look at the instructions here.