5

This is in my layout :

    <android.support.v7.app.MediaRouteButton
    android:id="@+id/button_fling"
    android:layout_gravity="center_vertical"
    android:layout_width="wrap_content"
    android:background="@drawable/mr_ic_media_route_holo_light"
    android:layout_height="wrap_content"       
    android:mediaRouteTypes="user"
    android:layout_weight="1"
    android:visibility="visible" />

and this in my my activity:

@Override

    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);
            mMediaRouter = MediaRouter.getInstance(getApplicationContext());
            mMediaRouteSelector = new MediaRouteSelector.Builder()
            .addControlCategory(CastMediaControlIntent.categoryForCast(getString(R.string.app_id)))
            .build();
            mMediaRouterCallback = new MyMediaRouterCallback();

            mMediaRouteButton = (MediaRouteButton) findViewById(R.id.button_fling);
            mMediaRouteButton.setRouteSelector(mMediaRouteSelector);
        button_fling2 = (ImageView)findViewById(R.id.button_fling2);
}



    public class MyMediaRouterCallback extends MediaRouter.Callback {
    public int mRouteCount =0;
    @Override
    public void onRouteAdded(MediaRouter router, RouteInfo route) {
        Log.d(TAG, "onRouteAdded");
        if (++mRouteCount == 1) {
            // Show the button when a device is discovered.
            Log.i(TAG,"MediaRoute is visible");
            button_fling2.setVisibility(View.VISIBLE);
            mMediaRouteButton.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onRouteRemoved(MediaRouter router, RouteInfo route) {
        Log.d(TAG, "onRouteRemoved");
        if (--mRouteCount == 0) {
            // Hide the button if there are no devices discovered.
            Log.i(TAG,"MediaRoute is GONE");
            button_fling2.setVisibility(View.GONE);
            mMediaRouteButton.setVisibility(View.GONE);
        }
    }

}

ButtonFling2 is an ImageView I am using to test MyMediaRouterCallback is working or not. It successfully hides/shows the imageView. However for button_fling(which is a mediaRouteButton instance) does not show anything. It's as if it can't find the resources of the MediaRouteButton so it is showing no cast icon... anyone ever fix this or come across this?

I don't get any errors it just simply does not show, but the logs show that it is visible and the ImageView i have for testing shows up.

reidisaki
  • 1,525
  • 16
  • 29
  • Where are you calling `setRouteTypes()`? – CommonsWare Mar 12 '14 at 23:59
  • thanks for the quick response, i'm not calling it anywhere :( I'm pretty much following the sample project here:: https://github.com/googlecast/MediaRouter-Cast-Button-android/blob/master/src/com/example/mediarouter/MediaRouterButtonActivity.java – reidisaki Mar 13 '14 at 00:00
  • Sorry -- typo in my comment. Where are you calling `setRouteSelector()`, and what is your selector? – CommonsWare Mar 13 '14 at 00:03
  • updated with more information :) I guess a more detailed question would be, why doesn't the mediaRouteButton pick up the standard cast drawables? stuff like : mr_ic_media_route_on_1_holo_light should be what it picks up in the support libraries.. but for some reason it doesn't find them or use them. – reidisaki Mar 13 '14 at 00:08
  • Does the GitHub MediaRouter-Cast-Button-android project for you without any modifications? – Leon Nicholls Mar 13 '14 at 00:27
  • just downloaded the app, the only modification I did was change the APP_ID. and the cast device and phone are on the same network.. the image doesn't show up in the sample app either. – reidisaki Mar 13 '14 at 00:56
  • Try one of our public app id's: 4F8B3483 – Leon Nicholls Mar 13 '14 at 21:30
  • will do, i tried.. still same issue :( stackoverflow.com/questions/18158715/… i'm having the same issue as this guy but I'm not using gradle. For some reason even if I add the MediaRouteButton to a view and set it as visible, it still won't even show. Thanks guys! Update - I also just tried to run other parts of the demo app and the mediaRouteButton simply does not wanna show! – reidisaki Mar 14 '14 at 03:50
  • Do any other Chromecast apps work on that same device and network? – Leon Nicholls Mar 14 '14 at 16:40
  • yes, I tested the Chromecast with netflix,pandora and it works, I also am testing the Chromecast hello text example, and the cast icon shows up there. For some reason the MediaRouteButton example doesn't work. The icon never shows up. I thought it was at first my support library setup, but if this were the case the helloText example wouldn't work either. So non actionBar examples dont work it seems. Thanks! – reidisaki Mar 14 '14 at 19:15

2 Answers2

2

AFter fiddling around with this thing, I was able to get the media Router button to show up. I am not entirely sure what I did but I did verify the appid and tried to use my whitelisted app id. I reinstalled the support library. THANK YOU ALL FOR WHO HELPED ON THIS!

I am not 100% sure how this happened but I hope that this helps someone figure out or at least get past this. ActionBar Activity and non action bar activities show the media router button now!!! :)

reidisaki
  • 1,525
  • 16
  • 29
0

Implementing onRouteChanged() callback instead of onRouteAdded() should fix the issue.

Example code:
    // for MediaRouterButtonActivity
        @Override
        public void onRouteChanged(MediaRouter router, RouteInfo route) {
          if (++mRouteCount == 1) {
                // Show the button when a device is discovered.
                mMediaRouteButton.setVisibility(View.VISIBLE);
          }
    }
Sreenu Yatam
  • 166
  • 4