MediaRouteButton 未显示 RemoteDisplay 应用程序 ID
MediaRouteButton not showing with RemoteDisplay Application ID
我正在为 android 开发一个 chromecast 应用程序,使用 sdk v2 实现 RemoteDisplay。
我的 MediaRouteButton
从未使用我在演员开发者控制台上为 RemoteDisplay
应用程序创建的应用程序 ID 显示在我的发现菜单上,但如果我使用 CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID
作为 ID,该按钮就会出现.
这是我的Activity:
public class MainActivity extends AppCompatActivity {
public final static String ID = "99FB28D7";
MediaRouter mediaRouter;
MediaRouteSelector mediaRouteSelector;
private CastDevice selectedDevice;
private MyMediaRouterCallback routerCallback = new MyMediaRouterCallback();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.mediaRouter = MediaRouter.getInstance(getApplicationContext());
this.mediaRouteSelector = new MediaRouteSelector.Builder()
.addControlCategory(CastMediaControlIntent.categoryForCast(ID)).build();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.main, menu);
MenuItem mediaRouteMenuItem = menu.findItem(R.id.media_route_menu_item);
MediaRouteActionProvider mediaRouteActionProvider =
(MediaRouteActionProvider) MenuItemCompat.getActionProvider(mediaRouteMenuItem);
mediaRouteActionProvider.setRouteSelector(this.mediaRouteSelector);
return true;
}
@Override
protected void onStart() {
super.onStart();
this.mediaRouter.addCallback(this.mediaRouteSelector, routerCallback, MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);
}
@Override
protected void onStop() {
this.mediaRouter.removeCallback(this.routerCallback);
super.onStop();
}
private class MyMediaRouterCallback extends MediaRouter.Callback {
@Override
public void onRouteSelected(MediaRouter router, MediaRouter.RouteInfo info) {
selectedDevice = CastDevice.getFromBundle(info.getExtras());
}
@Override
public void onRouteUnselected(MediaRouter router, MediaRouter.RouteInfo info) {
selectedDevice = null;
}
}
}
我的main.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_route_menu_title"
app:actionProviderClass="android.support.v7.
app.MediaRouteActionProvider"
app:showAsAction="always"/>
</menu>
我正在 Android Marshmallow 运行 GooglePlayServices 11.7.
我也试过降级 GooglePlayServices
到 10.2
,但仍然无法正常工作。
谢谢!
几周后,我再次尝试我的代码,一切正常。我不知道发生了什么,但我发现有人打开了这个问题:
https://issuetracker.google.com/issues/69470206。
可能有关系。
我正在为 android 开发一个 chromecast 应用程序,使用 sdk v2 实现 RemoteDisplay。
我的 MediaRouteButton
从未使用我在演员开发者控制台上为 RemoteDisplay
应用程序创建的应用程序 ID 显示在我的发现菜单上,但如果我使用 CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID
作为 ID,该按钮就会出现.
这是我的Activity:
public class MainActivity extends AppCompatActivity {
public final static String ID = "99FB28D7";
MediaRouter mediaRouter;
MediaRouteSelector mediaRouteSelector;
private CastDevice selectedDevice;
private MyMediaRouterCallback routerCallback = new MyMediaRouterCallback();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.mediaRouter = MediaRouter.getInstance(getApplicationContext());
this.mediaRouteSelector = new MediaRouteSelector.Builder()
.addControlCategory(CastMediaControlIntent.categoryForCast(ID)).build();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.main, menu);
MenuItem mediaRouteMenuItem = menu.findItem(R.id.media_route_menu_item);
MediaRouteActionProvider mediaRouteActionProvider =
(MediaRouteActionProvider) MenuItemCompat.getActionProvider(mediaRouteMenuItem);
mediaRouteActionProvider.setRouteSelector(this.mediaRouteSelector);
return true;
}
@Override
protected void onStart() {
super.onStart();
this.mediaRouter.addCallback(this.mediaRouteSelector, routerCallback, MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);
}
@Override
protected void onStop() {
this.mediaRouter.removeCallback(this.routerCallback);
super.onStop();
}
private class MyMediaRouterCallback extends MediaRouter.Callback {
@Override
public void onRouteSelected(MediaRouter router, MediaRouter.RouteInfo info) {
selectedDevice = CastDevice.getFromBundle(info.getExtras());
}
@Override
public void onRouteUnselected(MediaRouter router, MediaRouter.RouteInfo info) {
selectedDevice = null;
}
}
}
我的main.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_route_menu_title"
app:actionProviderClass="android.support.v7.
app.MediaRouteActionProvider"
app:showAsAction="always"/>
</menu>
我正在 Android Marshmallow 运行 GooglePlayServices 11.7.
我也试过降级 GooglePlayServices
到 10.2
,但仍然无法正常工作。
谢谢!
几周后,我再次尝试我的代码,一切正常。我不知道发生了什么,但我发现有人打开了这个问题:
https://issuetracker.google.com/issues/69470206。
可能有关系。