为什么我的MediaRouteButton无法找到任何演员表设备?
以下是我在主要活动中的代码
following are my codes in main activity
public class MainActivity extends ActionBarActivity{
private MediaRouteButton mMediaRouteButton;
private MediaRouteSelector mMediaRouteSelector;
private MediaRouter mMediaRouter;
private CastDevice mSelectedDevice;
private MyMediaRouterCallback mMediaRouterCallback;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(this.checkGooglePlaySevices(this))
Log.v("cc5zhenhua","googleplayservice okay");
else
{
Log.v("cc5zhenhua","googleplayservice not ok");
//GooglePlayServicesUtil.getErrorDialog(0, this, 0).show();
}
//initialize media cast objects
mMediaRouter=MediaRouter.getInstance(getApplicationContext());
mMediaRouteSelector=new MediaRouteSelector.Builder()
.addControlCategory(CastMediaControlIntent.CATEGORY_CAST).build();
mMediaRouterCallback= new MyMediaRouterCallback();
mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback);
}
public void onStart() {
super.onStart();
mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback
);
MediaRouter.RouteInfo route = mMediaRouter.updateSelectedRoute(mMediaRouteSelector);
// do something with the route...
}
@Override
protected void onResume()
{
super.onResume();
mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
super.onCreateOptionsMenu(menu);
//mMediaRouteButton.setRouteSelector(mMediaRouteSelector);
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu){
getMenuInflater().inflate(R.menu.main, menu);
MenuItem mediaRouteItem = menu.findItem( R.id.action_mediaroute01 );
MediaRouteActionProvider mediaRouteActionProvider =
(MediaRouteActionProvider)MenuItemCompat.getActionProvider(
mediaRouteItem);
mediaRouteActionProvider.setRouteSelector(mMediaRouteSelector);
mMediaRouteButton = (MediaRouteButton) mediaRouteItem.getActionView();
return true;}
public boolean checkGooglePlaySevices(final Activity activity) {
final int googlePlayServicesCheck = GooglePlayServicesUtil.isGooglePlayServicesAvailable(
activity);
switch (googlePlayServicesCheck) {
case ConnectionResult.SUCCESS:
return true;
default:
Log.v("cc5zhenhua","test"); }
return false;
}
private class MyMediaRouterCallback extends MediaRouter.Callback
{
@Override
public void onRouteSelected(MediaRouter router, RouteInfo info) {
mSelectedDevice = CastDevice.getFromBundle(info.getExtras());
String routeId = info.getId();
Log.v("cc5zhenhua", "MainActivity.onRouteSelected");
}
@Override
public void onRouteUnselected(MediaRouter router, RouteInfo info) {
//teardown();
mSelectedDevice = null;
}
}
}
没有构建错误。但是,当我运行主活动时,根本无法单击媒体路由按钮。请告诉我我想念的地方吗?谢谢!
There's no build error. However when I run the main activity, the media route button can not be clicked at all. Please advise any where I missed? Thank you!
在发布新的SDK之前,我的chromecast已通过APPID注册为白名单。
我也不能将那个appID用作控件类别,它不会抛出有效的appID异常。
My chromecast is whitelisted registed with an APPID before the new SDK published. I can't use that appID for the control category either, it throws not valida appID exception.
我的投射设备也可用于我的chromecast扩展
My cast device is also available for chromecast extension in my computer.
最后获得问题点。仅仅因为我最后一个带有旧googlecast sdk的应用程序可以在AVD上运行,所以我专注于代码和新的SDK设置。但是,当我在真实电话上部署该应用程序时,可以找到媒体路由。感谢阿里的友善和帮助。
Finally get the issue point. Just because that my last app with old googlecast sdk works on the AVD, so I focused on my codes and new SDK setting.However, when I deploy the app on real phone ,the media route can be found. Thanks to Ali for his kindness and helping.