Chromecast (Google Cast)
The Cast SDK allows a user to select streaming audio-visual content using a sender (Lura Player), and play it on (or cast it to) another device known as the receiver, while controlling playback using the sender.
Google Cast is not supported on tvOS.
To enable Google Cast SDK on your player, you need to do the following LuraChromecastConfiguration
configuration:
Attribute | Type | Optional | Description |
---|---|---|---|
enabled | boolean | true | Whether casting is enabled in available devices. (Defaults to false) |
appId | string | false | Chromecast receiver application ID |
let chromecastConfig = LuraChromecastConfiguration(enabled: true, appId: "YOUR_APP_ID")
let luraConfig = LuraPlayerConfiguration(
lura: .init(appKey: "APP_KEY", assetId: "ASSET_ID"),
cast: .init(chromecast: chromecastConfig)
)
luraPlayer?.setConfig(luraConfig)
Follow Official Documentation
For detailed guidance on configuring your sender app and handling permissions, please refer to the official Google Cast iOS Sender Documentation. This documentation provides comprehensive information on implementing the necessary permission prompts, such as local network access, which is required for successful device discovery.
Configure AppDelegate
In the AppDelegate class, you will need to add the necessary configuration code in the didFinishLaunchingWithOptions method. The following code initializes Google Cast options for the Lura Player SDK integration:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
#if os(iOS)
let receiverAppId = "59068AF6" // Use your custom application ID or the default ID provided here.
let criteria = GCKDiscoveryCriteria(applicationID: receiverAppId)
let options = GCKCastOptions(discoveryCriteria: criteria)
let launchOptions = GCKLaunchOptions(relaunchIfRunning: true)
options.launchOptions = launchOptions
options.suspendSessionsWhenBackgrounded = false
options.startDiscoveryAfterFirstTapOnCastButton = true
options.stopReceiverApplicationWhenEndingSession = true
options.physicalVolumeButtonsWillControlDeviceVolume = true
GCKCastContext.setSharedInstanceWith(options)
#endif
return true
}
This setup ensures that the necessary Google Cast options are correctly configured, including discovery and session management behaviors.
Add the Cast Button to Your User Interface
Once the previous steps are completed, you can add the Cast button to your user interface. The following code provides an example of how to configure and add the Cast button to your view:
import GoogleCast
import LuraPlayerSDK
private var buttonCast = GCKUICastButton()
// - Lifecycle: View
override func viewDidLoad() {
super.viewDidLoad()
setupCastButton()
}
private func setupCastButton() {
buttonCast.tintColor = .white
buttonCast.clipsToBounds = true
buttonCast.layer.cornerRadius = 4.0
NSLayoutConstraint.activate([
buttonCast.heightAnchor.constraint(equalToConstant: 44.0),
buttonCast.widthAnchor.constraint(equalToConstant: 44.0)
])
buttonCast.backgroundColor = UIColor.black.withAlphaComponent(0.25)
hStackTopRight.insertArrangedSubview(buttonCast, at: 0) // Add the Cast button to the desired view hierarchy.
}
When the Cast button is pressed for the first time, the user will be prompted for local network permission, ensuring a seamless experience for initiating casting.