当我从发件人应用程序连接到CC设备时,通常自定义接收器无法正常启动。
它将加载,但永远不会处于就绪状态。
这是logcat输出:
01-21 14:16:09.603 19396-19396/com.example.chromecast D/PlayActivity onRouteSelected
01-21 14:16:16.913 19396-19396/com.example.chromecast D/PlayActivity onConnected
01-21 14:16:16.953 19396-19396/com.example.chromecast D/ccl_BaseCastManager﹕ [v1.11] onConnected() reached with prior suspension: false
01-21 14:16:16.953 19396-19396/com.example.chromecast D/ccl_BaseCastManager﹕ [v1.11] launchApp() is called
01-21 14:16:16.953 19396-19396/com.example.chromecast D/ccl_BaseCastManager﹕ [v1.11] Launching app
01-21 14:16:17.003 19396-19396/com.example.chromecast D/ccl_DataCastManager﹕ [v1.11] onApplicationStatusChanged() reached:
01-21 14:16:19.513 19396-19396/com.example.chromecast D/ccl_DataCastManager﹕ [v1.11] onApplicationStatusChanged() reached: null
01-21 14:16:20.633 19396-19396/com.example.chromecast D/ccl_BaseCastManager﹕ [v1.11] launchApplication() -> failure result
01-21 14:16:20.633 19396-19396/com.example.chromecast D/ccl_BaseCastManager﹕ [v1.11] disconnectDevice(true,false)
01-21 14:16:20.633 19396-19396/com.example.chromecast D/ccl_BaseCastManager﹕ [v1.11] mConnectionSuspended: false
01-21 14:16:20.633 19396-19396/com.example.chromecast D/ccl_BaseCastManager﹕ [v1.11] clearPersistedConnectionInfo(): Clearing persisted data for 0
01-21 14:16:20.653 19396-19396/com.example.chromecast D/ccl_BaseCastManager﹕ [v1.11] onDisconnected() reached
01-21 14:16:20.653 19396-19396/com.example.chromecast D/ccl_BaseCastManager﹕ [v1.11] Trying to disconnect
01-21 14:16:37.295 19396-19396/com.example.chromecast D/PlayActivity ApplicationConnectionResultCallback.onResult: statusCode15
01-21 14:16:37.295 19396-19396/com.example.chromecast E/PlayActivity application could not launch
01-21 14:16:37.295 19396-19396/com.example.chromecast D/PlayActivity teardown
如果我在发件人应用程序中断开连接,然后重新连接,接收器将进入就绪状态,我可以投射我的内容。
导致此行为的原因是什么? (它经常发生,然而不是非常令人沮丧!)
一些代码:
(媒体路线初始化)
mMediaRouter = MediaRouter.getInstance(getApplicationContext());
mMediaRouteSelector = new MediaRouteSelector.Builder()
.addControlCategory(
CastMediaControlIntent.categoryForCast(getResources()
.getString(R.string.app_id))).build();
mMediaRouterCallback = new MyMediaRouterCallback();
mDataCastManager = DataCastManager.initialize(this, getResources().getString(R.string.app_id), getResources().getString(R.string.namespace));
mDataCastManager.reconnectSessionIfPossible(this, true, 20);
媒体路线按钮
@Override
public boolean onCreateOptionsMenu(Menu 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(mMediaRouteSelector);
return super.onCreateOptionsMenu(menu);
}
回调
private class MyMediaRouterCallback extends MediaRouter.Callback {
@Override
public void onRouteSelected(MediaRouter router, MediaRouter.RouteInfo info) {
Log.d(TAG, "onRouteSelected");
// Handle the user route selection.
mSelectedDevice = CastDevice.getFromBundle(info.getExtras());
launchReceiver();
}
@Override
public void onRouteUnselected(MediaRouter router, MediaRouter.RouteInfo info) {
Log.d(TAG, "onRouteUnselected: info=" + info);
teardown();
mSelectedDevice = null;
}
}
如您所见,我的大部分实现都来自CastHelloText Android示例应用程序。我已经在CCL库中添加了以便轻松进行会话管理,但我认为这会导致问题。
在连接CC设备进行投射时,注释掉DataCastManager似乎可以提供更好的结果。
答案 0 :(得分:0)
如果您正在使用CCL,则停止管理媒体路由器按钮,媒体路由器的直接回调,启动接收器等,因为这些是由CCL处理的。如果你想自己做这些事情,那就停止使用CCL;你目前正以错误的方式混合两种不同的东西。阅读CCL上的文档可能会有所帮助。