FLCastManager
public protocol FLCastManager
FLCastManager is a singleton responsible for setting up a custom channel for communication with a Cast session.
Usage
- Before communicating with a Cast session, the sender application must create a
GCKCastContextinstance:
DispatchQueue.main.async {
let criteria = GCKDiscoveryCriteria(applicationID: castReceiverId)
let gckOptions = GCKCastOptions(discoveryCriteria: criteria)
gckOptions.physicalVolumeButtonsWillControlDeviceVolume = true
GCKCastContext.setSharedInstanceWith(gckOptions)
GCKCastContext.sharedInstance().useDefaultExpandedMediaControls = true
}
After initializing
GCKCastContext, callinitialize()to add aGCKSessionManagerListenerand register the GCKLogger callback for the SDK.To receive
FLCastManagerDelegatecallbacks, set a confirmed instance ofFLCastManagerDelegateusingregisterListener(_:).To stop receiving callbacks, call
unregisterListener().Casting Content:
- Use a
CastPlayerinstance to initiate content playback. Before casting, register the Cast device with the Firstlight Platform by callingregisterUserData(clientDevice:castDeviceID:authToken:)after the Cast session has started. - After successful registration, load media on the receiver using
loadMedia(castAsset:metadata:mediaTracks:)from theCastPlayerAPI. - If registration fails, you will be notified with an error when attempting to load media.
- Use a
Cast Session Management:
- A Cast session includes connecting to a device, launching or joining a receiver application, and initializing a media control channel. Sessions start automatically when the user selects a device and end when disconnected. Reconnection due to network issues is handled by the Cast SDK.
-
The Google Cast context instance.
Declaration
Swift
var castContext: GCKCastContext { get } -
The Google Cast session manager instance.
Declaration
Swift
var castSessionManager: GCKSessionManager { get } -
The Cast player, equivalent to the remote media client in the Google Cast SDK.
Declaration
Swift
var castPlayer: FLCastPlayer? { get } -
Adds a
GCKSessionManagerListenerand registers the GCKLogger callback for the SDK.Note
Call afterGCKCastContextis initialized.Declaration
Swift
func initialize() -
Removes the
GCKSessionManagerListenerand ends the current session and casting.Declaration
Swift
func dispose() -
Registers a delegate to receive
FLCastManagerDelegatecallbacks.Declaration
Swift
func registerListener(_ delegate: FLCastManagerDelegate?) -
Unregisters the delegate to stop receiving
FLCastManagerDelegatecallbacks.Declaration
Swift
func unregisterListener() -
Sends user context or device information to the receiver. Should be called after session initialization for device registration, a prerequisite for content authorization.
Declaration
Swift
func registerUserData(clientDevice: PlatformClient, castDeviceID: String, authToken: String)Parameters
clientDeviceThe sender client device.
castDeviceIDThe cast device identifier.
authTokenThe user authentication token.
-
Sends a text message to the receiver. Can only be sent when a cast session is active.
Declaration
Swift
func sendMessage(payload: Message, completion: @escaping (GCKError?) -> Void)Parameters
payloadThe message to send.
completionCalled on the main thread with a
GCKErroron failure, ornilon success. -
presentExpandedController(disableSeek:Default implementation) Presents the default expanded media controls UI for the current Cast session.
Configures and displays the default expanded media controls provided by the Google Cast SDK. Call this to present the standard media controls interface for the active Cast session. The expanded controller allows users to interact with playback, volume, and other media controls on the cast device. Applicable only for live content.
Default Implementation
Presents the default expanded media controls UI for the current Cast session.
Configures and displays the default expanded media controls provided by the Google Cast SDK. Call this to present the standard media controls interface for the active Cast session. The expanded controller allows users to interact with playback, volume, and other media controls on the cast device. Applicable only for live content.
Declaration
Swift
func presentExpandedController(disableSeek: Bool?)Parameters
disableSeekIf true, disables seek controls in the expanded controller.
-
Returns the connected cast device name.
Declaration
Swift
func getDeviceName() -> String?Return Value
The device name if a cast session is active; otherwise nil.