当我从Sender应用程序连接到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


如果我在Sender应用程序中断开连接,然后重新连接,Receiver将进入就绪状态,我可以投射内容。

是什么导致这种行为? (它发生的次数多于没有发生,而且非常麻烦!)

一些代码:

(媒体路由初始化)

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似乎会提供更好的结果。

最佳答案

如果使用的是CCL,请停止管理媒体路由器按钮,来自媒体路由器的直接回调,启动接收器等,因为这些都是由CCL处理的。如果您想自己做这些事情,请停止使用CCL。您当前正在以错误的方式混合两种不同的事物。阅读有关CCL的文档可能会有所帮助。

08-05 06:23