Search code examples
iosswiftchromecastgoogle-cast

How to get GCKViewVideoFrameInput working in swift?


Trying to mirror views to chromecast with the remote display API. On Android it is well documented and easy to implement. The iOS samples/docs are less complete. I understand it only supports 15 fps but that is fine for my needs.

If anyone has gotten it to work, I'd love to see a small swift sample that shows how to mirror a simple view. I'm trying to test it with this, which shows nothing on the TV and gives the device has disconnected after a few seconds. From reading the docs, that happens when you don't send anything within the first 15 secs of getting the session.

    var testSession: GCKRemoteDisplaySession!

    func remoteDisplayChannel(channel: GCKRemoteDisplayChannel,
    didBeginSession session: GCKRemoteDisplaySession) {
        // Use the session.
        testSession = session
        frameInput = GCKViewVideoFrameInput(session: testSession)
        // any view
        frameInput.view = testView        
    }

Solution

  • Make sure you are strongly referencing the session as well as the frame input. Inputs have weak references to sessions (to avoid cycles between sessions and inputs). If the session is not strongly referenced and gets destroyed, you'll see black on your remote screen followed by a timeout disconnect.