Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android.support.v7.app.MediaRouteButton does not display

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.

like image 820
reidisaki Avatar asked Nov 01 '22 03:11

reidisaki


1 Answers

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!!! :)

like image 137
reidisaki Avatar answered Nov 11 '22 11:11

reidisaki