Enable Chromecast on the Sender on iOS
This article explains how to enable the Chromecast Sender capabilities. This article also documents how you can connect with a custom Chromecast Receiver application.
Prerequisites
- Your Sender device needs to be on the same Wi-Fi network as your Chromecast Receiver device.
Add the Chromecast integration
Add the THEOplayer GoogleCast integration and the Google Cast SDK to your project, as described in the installation section of the Chromecast introduction.
Next, set up the Cast Framework, as documented at https://developers.google.com/cast/docs/ios_sender_setup.
Changes to iOS 14 local network access permissions have impacted the Google Cast iOS SDK in a number of ways. Please see the iOS 14 Changes document to see how your app is affected.
Because the THEOplayer iOS SDK is a Dynamic Framework, it should not include any dependency frameworks on which it relies (e.g. the Chromecast SDK). Instead, developers should include the dependencies on which THEOplayer relies. Therefore, using a Dynamic Framework ensures that there are no symbol clashes.
Set GCKCastContext
To enable Chromecast on iOS the GCKCastContext shared instance should be set with a GCKCastOptions.
let options = GCKCastOptions(receiverApplicationID: "A1B2C3D4")
GCKCastContext.setSharedInstanceWith(options)
Or use the default THEOplayer cast options, which connect with the default THEOplayer Chromecast Receiver application:
THEOplayerGoogleCastIntegration.CastIntegrationHelper.setGCKCastContextSharedInstanceWithDefaultCastOptions()
That's it. When Chromecast-enabled devices are discovered, the player will display a Chromecast button. The player also works nicely together with the Chromecast controls that are part of the Chromecast Framework, (e.g. GCKUICastButton or the mini controller).
Connect with custom Chromecast Receiver application
The THEOplayer SDK on your Sender application connects with THEO Chromecast Receiver application by default,
but you can connect it to a custom Chromecast Receiver application instead. The default Dolby OptiView Chromecast Receiver application has OptiView Player functionality, but uses Shaka for media playback. If you want to use Google's legacy Media Player Library (MPL) for playback, you will need to use either a custom application or connect to Dolby OptiView's MPL Receiver application, using the appID value of 44BAE7D1. Note that the MPL receiver does not support HLS-CMAF streams.
By default, THEOplayer's Receiver app will be set when you call CastIntegrationHelper.setGCKCastContextSharedInstanceWithDefaultCastOptions().
You can connect with a custom Receiver app by configuring its ID through GCKCastContext.setSharedInstanceWith(GCKCastOptions(receiverApplicationID: "A1B2C3D4")).
This approach is further demonstrated at https://github.com/THEOplayer/samples-ios-sdk/tree/master/Native-GoogleCast.