Secure Playback
Create Platform Authorizer
The PlatformCore
or PlatformAuthorizer
facilitates seamless interaction with all nexgen 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, 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
val platformAuthConfig = PlatformAuthConfig.Builder()
.id("clientID")
.secret("clientSecret")
.xClientId("Quickplay-main-androidmobile")
.tokenEndPointURL("https://sample.com")
.build()
// Implement UserAuthorizationDelegate and use it to create PlatformAuthorizer
val platformAuthorizer = PlatformAuthorizer.Builder()
.withConfig(platformAuthConfig)
.userAuthorizationDelegate(userAuthDelegate)
.build(context)
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.
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 PlatformClient
PlatformClient
provides platform specific identifying information for a given device. It is recommended to use the DefaultDeviceInfoPlatformClient
method to create an instance of PlatformClient
.
Using DefaultDeviceInfoPlatformClient
populates all other relevant info (Device model, Device manufacturer, Android version, etc.) automatically. If the application wants to override any of the default values, they can do so by passing the desired value to the method.
val deviceId = "myDeviceId"
val platformClient = DefaultDeviceInfoPlatformClient(deviceId)
Applications are required to persist the PlatformClient
instance to identify the same device on subsequent sessions.
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 ContentAuthorizer
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 Quickplay Player
.
// Content Authorizer creation
val contentAuthorizer = ContentAuthorizer.Builder(
platformTestHelper.context,
clientRegistrationEndPoint,
contentAuthorizationEndPoint
).platformClient(platformClient)
.build()
It is suggested to create contentAuthorizer during start of application and invoke ContentAuthorizer.ensureDeviceRegistration
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.
A contentAuthorizer 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 a goal 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
val platformAsset = PlatformAsset(
contentID,
MediaType.DASH,
consumptionType,
catalogType,
DrmType.WIDEVINE
)
The created asset - either for streaming or download - must be authorized with the Quickplay platform to obtain a
ContentAuthorizationToken
.
when (val result = contentAuthorizer.authorizePlayback(platformAsset, null)) {
is Result.Failure -> {
val error = result.value
// handle authorization error as required
}
is Result.Success -> {
val contentAuthorizationToken = result.value
// use ContentAuthorizationToken to build the player
// and to set up other functionalities as required
}
}
The ContentAuthorizationToken
has content metadata such as content url, license url, licenseToken, mediaFormat and drmType. The asset can be used with Quickplay Player library for playback or download.
Start Playback
A Player instance could be created by supplying player builder properties like contentURL, mediaType, drmScheme, etc to PlayerBuilder class.
const val DEFAULT_CLIENT_AGENT = "FLClientAgent"
val player = PlayerBuilder()
.mediaURL(contentURL)
.mediaType(mediaType)
.drmScheme(drmScheme)
.drmLicenseURL(licenseURL ?: "")
.userAgent(DEFAULT_CLIENT_AGENT)
.playbackProperties(PlaybackProperties(
preferredMinBufferDurationMs = DEFAULT_MIN_BUFFR_DURATION))
.build(getApplication())
player.play()