Skip to main content

Secure Playback

Create Platform Authorizer

The PlatformCore or PlatformAuthorizer facilitates seamless interaction with all Quickplay platform services with industry standard security model. It is suggested to create one instance of platform authorizer and use it for one app session.

To create an instance of Platform Authorizer, one would require client Id, client secret, xClientId, authorization endPoint and User Authorization Delegate. The client Id and secret would be provided while onboarding a customer onto Quickplay platform. The client app must implement and provide user authorization delegate which delivers the UMS token required for authorization with platform services.

The endPoints would be provided to a customer while onboarding onto Quickplay platform.

// Platform Authorizer creation snippet
let configuration = FLPlatformCoreFactory.authorizerConfiguration(
clientId: clientId,
clientSecret: clientSecret,
xClientId: xClientId,
tokenEndPoint: endPoint)

// Implement UserAuthorizationDelegate and use it to create PlatformAuthorizer
let platformAuthorizer = FLPlatformCoreFactory.authorizer(
configuration: configuration,
userAuthorizationDelegate: userAuthorizationDelegate)
note

At any point of time only one instance of PlatformAuthorizer could be created and it is suggested to use this instance for the complete application session. The existing PlatformAuthorizer instance must be disposed by calling platformAuthorizer.dispose() before creating a new one.

danger

The application owns the responsibility of returning valid user token through the userAuthorizationDelegate implementation. Whenever there is a change in user using the application, the user token must be refreshed accordingly.

Create Platform Client

The content authorizer is married to one particular device, Quickplay client library provides an API to generate a unique PlatformClient instance which gives access to a unique device id.

protocol PlatformClient {
/// Unique identifier of the client or device.
var id: String { get }
/// Name of the client or device.
var name: String { get }
}

A unique instance of PlatformClient can be generated as shown below. Applications are required to persist the generated platform client instance to identify the same device on subsequent sessions.

func getPlatformClient() -> PlatformClient {
guard let device = cachedPlatformClient() else {
let newDevice = FLPlatformCoreFactory.createDevice()
savePlatformClient(newDevice)
return newDevice
}

return FLPlatformCoreFactory.createDevice(id: device.id, name: device.name)
}

Create Content Authorizer

The ContentAuthorization library assists with authorizing an asset for either playback or download. To create an instance of content authorizer one would need platform authorizer, device registration endPoint, content authorization endPoint and a client device.

The content authorizer expects PlatformAsset which represents a potential playable asset and type of delivery for which authorization is seeked. The delivery type could be streaming or download. Upon successful authorization, PlaybackAsset is obtained, which could be used to play with our Player.

// Content Authorizer creation
let contentAuthConfig = FLContentAuthorizerFactory.contentAuthorizerConfiguration(
endPoint: contentAuthEndPoint,
deviceRegistrationEndPoint: deviceRegistrationEndPoint)

let client = FLPlatformCoreFactory.createDevice(id: "test-device-edgeservices-123")

let contentAuthorizer = FLContentAuthorizerFactory.contentAuthorizer(
configuration: contentAuthConfig,
device: client,
platformAuthorizer: platformAuthorizer)
note

It is suggested to create contentAuthorizer during start of application and invoke contentAuthorizer.registerDevice ensuring device registration prior to content authorization. If not done, contentAuthorizer would automatically register device prior to the very first content authorization request. Performing device registration at app launch would optimise authorization response time during the first authorization request. There is no limit on contentAuthorizer instance creation, however, it is suggested to use one instance for the complete application session.

danger

A contenAuthorizer is tied to a single device(PlatformClient) and user during its life time. Whenever there is a change with user using the application or change in deviceId(when deviceId was provided while constructing PlatformClient), it is mandatory to re-register the device.

Authorize Playback

The player library is designed with goals to facilitate playback by content url and to provide utmost control for integrators.

A PlatformAsset could be constructed with APIs from ContentAuthorizer providing the following:

  • Content Id: Unique identifier of the content
  • Media Format: HLS | DASH | SmoothStream
  • DRM: Fairplay | Widevine
  • Catalog Type: movie | tvepisode | shortvideo | sportshow | sporthighlight | sportclip | sportevent | sportsliveevent | channel | event
  • Content Type: VOD | Live
// create asset
let asset = FLContentAuthorizerFactory.platformAsset(contentId: contentId,
contentType: .vod,
catalogType: "movie",
mediaFormat: .hls,
drm: .fairplay)

The created asset must be authorized with the Quickplay platform to obtain a PlaybackAsset.

// authorize asset
contentAuthorizer.authorizeContent(asset: asset, delivery: .streaming) {
(result: Result<PlaybackAsset, Error>) in
switch result {
case let .success(playbackAsset):
// Create player and play
case let .failure(error):
// handle authorization failure error
}
}

Start Playback

A Player instance could be created supplying a content URL or an AVURLAsset. The later is preferred for playing protected content, so that license fetching could be configured for the same AVURLAsset.

// Creating Player
if let contentURL = URL(string: playbackAsset.contentUrl) {
let avURLAsset = AVURLAsset(url: contentURL)
let player = FLPlayer.player(asset: avURLAsset)
// add player's playback view to your controller
// player.playbackView
player.play()
}