Skip to main content

Chromecast

Chromecast on Quickplay platform qualifies as a device on its own and can perform device registration, content authorization and playback similar to any other conventional devices. The client sender facilitates sharing required information for device registration and content authorization to the receiver and the receiver processes the same for playback.

Cast Media

Casting a media using Quickplay platform requires the following to be performed in a sequence:

  • Initialize Cast Manager
  • Send User Device Information message to Receiver
  • Load Media onto Receiver

Please note, the above sequence of steps needs to be performed invariably for a new cast session inclusive of both Connect & Play and Play & Connect scenarios. It is advised that the initialization of cast manager and sharing user device information be performed during application launch and load media be performed on demand.

Initializing Cast Manager

Initializing the FLCastManager is the first and foremost step while integrating FLChromecast library and it is advised to perform initialization right at application launch. To initialize cast manager one must provide GCKCastOptions, the sender client device PlatformClient information with PlatformAuthorizer and custom channel namespace which would be used for sender receiver communications. The initialization callbacks could be received via FLCastManagerDelegate.


// GCK Options
let criteria = GCKDiscoveryCriteria(applicationID: <Receiver_Application_Id>)
let options = GCKCastOptions(discoveryCriteria: criteria)

// Set delegate to receive callbacks from CastManager
FLChromecastFactory.sharedCastManager.delegate = self
FLChromecastFactory.sharedCastManager.initialize(gckOptions: options, clientDevice: clientDevice, platformAuthorizer: platformAuthorizer, channelNamespace: <Channel_Namespace>)

// Attempt to initialize CastManager might result in either of the two delegate callbacks
// - func castManagerDidStart(session: GCKCastSession)
// - func castManagerDidFailToStart(session: GCKSession, withError error: Error)

Send User Device Information

Once a session has been established successfully, one must share the User Device Information to the Receiver. This is a mandate step, so that the receiver can register the device with Quickplay platform and perform authorization while loading media.

CastPlayer is available now and one can register for player delegate callbacks. The device registration and content authorization failures would be notified using cast player delegate callbacks.


// Send user device information to Receiver on Cast Manager initialization delegate callback

func castManagerDidStart(_: GCKCastSession) {
// Set delegate to receive callbacks
FLChromecastFactory.sharedCastManager.castPlayer?.delegate = <Player_Delegate>
// Send User device information
FLChromecastFactory.sharedCastManager.sendUserDeviceInformationMessage { (error: GCKError?) in
if error != nil {
// Sending user information failed! Check error.
} else {
// User Device Information sent successfully!
}
}
}

Load Media

The Cast Player with Cast Manager is analogous to the remote media player of Receiver. The same is available upon successful initialization of Cast Manager. To load media one should create a PlatformAsset which describes the media that needs to be authorized with Quickplay platform and played upon successful authorization. One can load GCKMediaMetadata and GCKMediaTrack optionally while loading media.

Analytics Data

Custom metadata can be sent to newrelic via loadMedia API through 'flAnalyticsData'. Similarly custom metadata can be sent to video analytics via loadMedia API through 'videoAnalyticsData'.

// configure metadata
let metadata = GCKMediaMetadata()
// Create PlatformAsset
let contentId = <Content_ID>
let contentType: ContentType = .vod
let catalogType: CatalogType = .movie
let mediaFormat: MediaFormat = .dash
let drm: DRM = .widevine
let asset = FLContentAuthorizerFactory.platformAsset(contentId: contentId, contentType: contentType, catalogType: catalogType, mediaFormat: mediaFormat, drm: drm)
// sends data to newrelic
let flAnalyticsData = [
'appBuild': 'test_id',
'channelID': 'D6C06257-3532-4431-93AB-C55A38f9EF0',
'contentID': 'SH021648050000',
'contentName': 'content-title',
'channelName': 'Sports HD',
'pageID': 'MyContent',
'seriesName': '',
'serviceID': '',
'silentLogin': 'true',
'tabName': 'movies',
],
// sends data to conviva
let videoAnalyticsData = [
'viewerId': 'userID / mobileNumber / emailId', // mandatory
'assetName': 'Name of the content', //mandatory
'tags': customTags, // customTags is a Key value pair that provide additional information about the content and it is optional.
]
FLChromecastFactory.sharedCastManager.castPlayer?.loadMedia(asset: asset, metadata: metadata, mediaTracks: mediaTracks, headers: headers, flAnalyticsData: flAnalyticsData, videoAnalyticsData: videoAnalyticsData)

The above snipped demonstrates creating a DASH/Widevine Movie content for authorization and playback. The supported combinations might differ based on individual projects. The Receiver upon receiving this information attempts to authorize the asset with Quickplay platform and plays the content.

note

Please refer FLContentAuthorizer documentation to read more on creating PlatformAsset

Cast Player and Events

The CastPlayer extends Player interface and provides the benefit of having same APIs as conventional Player from FLPlayer library. Some of the player APIs are no-op with CastPlayer, due to constraints with underlying player, Remote Media Client in this case.

The following APIs with Player interface are no-op as of today:

  • replaceAsset(:)
  • load()
  • seek(to date:)
  • all PiP APIs
  • all track manipulation APIs accepting MediaType
  • set(preferences:)
// access remote player
FLChromecastFactory.sharedCastManager.castPlayer

To listen to player events, implement the player delegate and listen for callbacks. Media load failures will also be notified via player delegate.

Cast Player UI

FLChomecast library does not wrap GoogleCast SDK to provide all functionalities that GoogleCast SDK offers. UI components from GoogleCast SDK can be used to render cast buttons. The integrators have complete control over player UI rendering and can enjoy the same luxury of integrating GoogleCast SDK directly. Most of the integrators prefer using their own UI for player which can double up as remote Cast Player and local Player. The integration is a breeze due to the fact that both players, FLPlayer(local playback) and CastPlayer(Remote playback) has same public interface.

E2E Integration

Here is the snippet comprising all the above sequence of steps.


//********** Initialize cast Manager at app launch *********

// GCK Options
let criteria = GCKDiscoveryCriteria(applicationID: <Receiver_Application_Id>)
let options = GCKCastOptions(discoveryCriteria: criteria)

// Set delegate to receive callbacks from CastManager
FLChromecastFactory.sharedCastManager.delegate = self
FLChromecastFactory.sharedCastManager.initialize(gckOptions: options, clientDevice: clientDevice, platformAuthorizer: platformAuthorizer, channelNamespace: <Channel_Namespace>)

//********** Send user device information to Receiver on Cast Manager initialization delegate callback *********

func castManagerDidStart(_: GCKCastSession) {
// Set delegate to receive callbacks
FLChromecastFactory.sharedCastManager.castPlayer.delegate = <Player_Delegate>
// Send User device information
FLChromecastFactory.sharedCastManager.sendUserDeviceInformationMessage { (error: GCKError?) in
if error != nil {
// Sending user information failed! Check error.
} else {
// User Device Information sent successfully!
}
}
}

//********** Load Media *********

// configure metadata
let metadata = GCKMediaMetadata()
// Create PlatformAsset
let contentId = <Content_ID>
let contentType: ContentType = .vod
let catalogType: CatalogType = .movie
let mediaFormat: MediaFormat = .dash
let drm: DRM = .widevine
let asset = FLContentAuthorizerFactory.platformAsset(contentId: contentId, contentType: contentType, catalogType: catalogType, mediaFormat: mediaFormat, drm: drm)
// sends data to newrelic
let flAnalyticsData = [
'appBuild': 'test_id',
'channelID': 'D6C06257-3532-4431-93AB-C55A38f9EF0',
'channelName': 'Sports HD',
'contentID': 'SH021648050000',
'contentName': 'content-title',
'pageID': 'MyContent',
'seriesName': '',
'serviceID': '',
'silentLogin': 'true',
'tabName': 'movies',
],
// sends data to conviva
let videoAnalyticsData = [
'viewerId': 'userID / mobileNumber / emailId', // mandatory
'assetName': 'Name of the content', //mandatory
'tags': customTags, // customTags is a Key value pair that provide additional information about the content and it is optional.
]
// sends ad metadata
let customAdMetadata = [
'idType': 'The type of device.(eg: 'idfa')', // mandatory
'rdId': 'Apple IDFA (eg: '123e4567-e89b-12d3-a456-426655440000')', //mandatory
'isLat': 'Limit Ad Tracking (LAT) lets users to opt-out and therefore restrict advertisers from targeting based on user behavior. (eg: boolean either 0 or 1)' //mandatory
]
FLChromecastFactory.sharedCastManager.castPlayer?.loadMedia(asset: asset, metadata: metadata, mediaTracks: mediaTracks, headers: headers, flAnalyticsData: flAnalyticsData, videoAnalyticsData: videoAnalyticsData, customAdMetadata: customAdMetadata)