I know its a quite common problem although searching through stackoverflow and android developers site left me without whole picture.
CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID
, can I?I belive the problem lies there but still here's the code. Probably Cast Button doesn't show for some other reason.
Manifest:
...
android:theme="@style/Theme.AppCompat">
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
...
Media Router menu, media_router.xml
:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/media_route_menu_item"
android:title="@string/media_router_menu_title"
app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
app:showAsAction="always"/>
</menu>
Graddle dependencies:
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:mediarouter-v7:21.0.0'
compile 'com.google.android.gms:play-services:7.3.0'
buildMediaRouter() called in onCreate()
:
private void buildMediaRouter(){
mMediaRouter = MediaRouter.getInstance(getApplicationContext());
// Create a route selector for the type of routes your app supports.
mMediaRouteSelector = new MediaRouteSelector.Builder()
.addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO)
.addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO)
.addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
//default app ID because I don't need custom Receiver
.addControlCategory(CastMediaControlIntent.categoryForCast(CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID))
.build();
}
Creating options menu:
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
super.onCreateOptionsMenu(menu);
// Inflate the menu and configure the media router action provider.
getMenuInflater().inflate(R.menu.media_router, menu);
// 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(mMediaRouteSelector);
return true;
}
Appreciating any help.
To answer your questions:
After registering your cast device, wait a few minutes and reboot your device so it can pick up the new configuration. One common issue is registering the right serial number for your cast device, it is easy to mistake 0 and O, etc so take a photo of the serial number and zoom in to read the value.