3

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?

Fabii
  • 3,820
  • 14
  • 51
  • 92
  • Have you registered an App Id? Has your device been whitelisted for your app? Check to see if you can open your browser to http://:9222, if you can't, then your device is not whitelisted. In that case, you might want to follow instructions here: http://stackoverflow.com/a/21619494/2765813 – Ali Naddaf Feb 20 '14 at 16:13
  • Yes I have registered an App Id. Where do I locate the chromecast-ip? – Fabii Feb 20 '14 at 16:15
  • Use the Chromecast set up app on Android; it should show the ip address of the device – Ali Naddaf Feb 20 '14 at 16:16
  • Use the actual Chromecast app ? – Fabii Feb 20 '14 at 16:23
  • https://play.google.com/store/apps/details?id=com.google.android.apps.chromecast.app&hl=en – Ali Naddaf Feb 20 '14 at 16:42
  • Yep downloaded the app and looked up IP . Tried http://:9222 from chrome browser on my device and was unable to reach it. – Fabii Feb 20 '14 at 16:50
  • 1
    Then it is not whitelisted, please follow my earlier instructions. – Ali Naddaf Feb 20 '14 at 16:57
  • @AliNaddaf please put this as an answer so I can accept it :) – Fabii Feb 21 '14 at 19:25

1 Answers1

4

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

Community
  • 1
  • 1
Ali Naddaf
  • 16,951
  • 2
  • 21
  • 28
  • Also, do not forget that, after whitelisting of the device, you need to reboot it in order for the whitelist to take effect. – Martin Vysny Jul 02 '15 at 12:20