【问题标题】:Can not get GCKRemoteMediaClientListener called on second time无法第二次调用 GCKRemoteMediaClientListener
【发布时间】:2018-09-11 11:21:37
【问题描述】:

我正在使用googlecast sdk iOS 4.0.2 版本在同一wifi网络下寻找可投射设备,iOS版本为10.0或以上。

我创建了一个单例,并注册了监听器,当第一次找到设备时成功调用它。 之后就不能再调用了。

因为我不需要自动启动,所以下面是我初始化castcontext的代码。

    let criteria = GCKDiscoveryCriteria.init(applicationID: kGoogleCastApplicationID)
    let options = GCKCastOptions.init(discoveryCriteria: criteria)
    options.disableDiscoveryAutostart = false
    options.stopReceiverApplicationWhenEndingSession = true
    GCKCastContext.setSharedInstanceWith(

我将其设置为 false 是因为 sdk 中有以下注释。

/** * A flag indicating whether the discovery of Cast devices should start automatically at * context initialization time. If set to <code>NO</code>, discovery can be started and stopped * on-demand by using the methods GCKDiscoveryManager::startDiscovery and * GCKDiscoveryManager::stopDiscovery. * * @since 3.4 */

这是我开始和停止它的方法。

开始

    func startDiscovery() {
        if !discoveryManager.discoveryActive {
            registerDiscover()
            discoveryManager.startDiscovery()
        }
    }

停止

    func stopDiscovery() {
        if discoveryManager.discoveryActive {
            removeDicover()
            discoveryManager.stopDiscovery()
        }
    }

还有一件更奇怪的事情是,当应用程序在前台和后台之间切换时,我在控制台上看到TIC Read Status [5:0x0]: 1:57,现在我的代表被调用了。无论如何,这无济于事。

任何人都可以帮助我正确使用 googlecast sdk 手动启动和停止它。

提前致谢。

【问题讨论】:

  • 为什么需要手动启动和停止?最好是让 SDK 管理发现。
  • @LeonNicholls 因为我们在特定视图中才需要此功能。我们仅使用 GoogleCast 来发现已经满足我们要求的设备。有什么好的建议吗?
  • Cast 发送者的典型用例是从应用程序开始就启用该功能,并使其在所有带有媒体的屏幕上可用。如果您的用例不同,那么您将不得不尝试解决方案。
  • @LeonNicholls 看起来 sdk 中的 cmets 并不完全可信,这让我很困惑。还是非常感谢。

标签: ios swift google-cast google-cast-sdk


【解决方案1】:

我终于解决了这个问题。 上面的代码是正确的,SDK中的cmets没有错,但最好指出当再次开始发现时,我们不会收到之前发现的设备的通知,这意味着我们需要一个容器来保存设备我们手动获取并控制它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-20
    • 2018-09-20
    相关资源
    最近更新 更多