gpt4 book ai didi

java - 自定义接收器无法正确启动

转载 作者:太空宇宙 更新时间:2023-11-04 14:12:59 25 4
gpt4 key购买 nike

当我从发送器应用程序连接到 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 库中添加了内容以方便进行 session 管理,但我认为这就是导致问题的原因。

在连接 CC 设备进行转换时,注释掉 DataCastManager 似乎可以提供更好的结果。

最佳答案

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

关于java - 自定义接收器无法正确启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28069472/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com