Secure Playback
Create platform authorizer
PlatformCore or PlatformAuthorizer facilitates seamless interaction with
all Quickplay platform services with an industry-standard security model.
Create one instance of the platform authorizer and use it for one app session.
To create an instance of the platform authorizer, you need the following: client ID, client secret, xClientId, authorization endpoint, headers (optional), and user authorization delegate. You receive the client ID and secret when onboarding to the Quickplay platform. Your client app must implement and provide a user authorization delegate that delivers the UMS token required for authorization with platform services.
You receive the endpoints when onboarding to the Quickplay platform.
// Platform authorizer creation snippet
let configuration = FLPlatformCoreFactory.authorizerConfiguration(
clientId: clientId,
clientSecret: clientSecret,
xClientId: xClientId,
tokenEndPoint: endPoint,
headers: headers)
// Implement UserAuthorizationDelegate and use it to create PlatformAuthorizer
let platformAuthorizer = FLPlatformCoreFactory.authorizer(
configuration: configuration,
userAuthorizationDelegate: userAuthorizationDelegate)
Note: At any point in time, only one instance of
PlatformAuthorizercan be created. Use this instance for the complete application session. Dispose of the existingPlatformAuthorizerinstance by callingplatformAuthorizer.dispose()before creating a new one.
Warning: Your application is responsible for returning a valid user token through the
userAuthorizationDelegateimplementation. Whenever the user changes, refresh the user token accordingly.
Create platform client
The content authorizer is tied to one particular device. The Quickplay client
library provides an API to generate a unique PlatformClient instance that
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)
}
You must persist the generated platform client instance to identify the same device in subsequent sessions.
Create content authorizer
The ContentAuthorization library helps with authorizing an asset for either
playback or download. To create an instance of the content authorizer, you
need the following: platform authorizer, device registration endpoint, content
authorization endpoint, and a client device.
The content authorizer expects a PlatformAsset that represents a potential
playable asset and the type of delivery for which authorization is requested.
The delivery type can be streaming or download. Upon successful authorization,
you receive a PlaybackAsset that you can use to play with the player.
// Create content authorizer
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: Create the content authorizer at application startup and invoke
contentAuthorizer.registerDeviceto ensure device registration before content authorization. If you don't do this, the content authorizer automatically registers the device before the first content authorization request. Performing device registration at app launch optimizes authorization response time during the first authorization request. There's no limit on content authorizer instance creation, but use one instance for the complete application session.
Warning: A content authorizer is tied to a single device (
PlatformClient) and user during its lifetime. Whenever the user changes or the device ID changes (when you provide a device ID while constructingPlatformClient), you must re-register the device.
Authorize playback
The player library is designed to facilitate playback by content URL and to provide control for integrators.
You can construct a PlatformAsset with APIs from ContentAuthorizer by
providing the following:
- Content ID: Unique identifier of the content
- Media format: HLS, DASH, or SmoothStream
- DRM: FairPlay or Widevine
- Catalog type: movie, tvepisode, shortvideo, sportshow, sporthighlight, sportclip, sportevent, sportsliveevent, channel, or event
- Content type: VOD or Live
// Create asset
let asset = FLContentAuthorizerFactory.platformAsset(contentId: contentId,
contentType: .vod,
catalogType: "movie",
mediaFormat: .hls,
drm: .fairplay)
Authorize the created asset 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
You can create a player instance by supplying a content URL or an
AVURLAsset. Use AVURLAsset for playing protected content so you can
configure license fetching for the asset.
// Create 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()
}