Skip to main content

Secure Playback

Create Platform Authorizer​

PlatformCore and PlatformAuthorizer provide secure access to Quickplay platform services. Create one PlatformAuthorizer per app session.

createPlatformAuthorizer requires a client ID and secret, xClientId, an authorization endpoint, and a user authorization delegate. Headers are optional. Quickplay provides the credentials and endpoint during onboarding; your delegate supplies the UMS token.

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

// Platform Authorizer creation snippet
const platformConfig = {
clientID: clientId,
clientSecret: clientSecret,
xClientId: xClientId,
authorizationEndPoint: endPoint,
headers: {
// Optional custom request headers String key-value pair.
// Use this to inject backend-specific metadata or identifiers.
'X-Property-Id': 'string-value',
},
// Optional. Only set this if your OAuth token endpoint expects custom headers.
// oauthHeaders: { 'X-Property-Id': 'string-value' },
};

// Implement UserAuthorizationDelegate and use it to create PlatformAuthorizer
const platformAuthorizer = flPlatformAuthorizer.createPlatformAuthorizer(
platformConfig,
{
fetchUserAuthorizationToken: () => {
return { accessToken: accessToken };
},
},
);
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.

warning

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.

Custom Request Headers​

PlatformConfig accepts two optional sets of custom headers. Each set goes to a different group of requests.

PropertySent with
headersAuthorized platform requests (content authorization, client registration, bookmarks, heartbeat, stream concurrency, and license renewal) and DRM license requests.
oauthHeadersOAuth token requests to authorizationEndPoint only.

Custom headers trigger a CORS preflight in the browser. Make sure each endpoint lists your headers in its Access-Control-Allow-Headers response; otherwise the browser blocks the request. Set oauthHeaders only when your token endpoint expects custom headers and allows them.

warning

From Web SDK 7.1.302, headers is no longer sent with OAuth token requests. If your token endpoint relies on a header you set in headers, add the same header to oauthHeaders.

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.

interface PlatformClient {
/**
* Unique identifier of the client or device.
*/
id: string;

/**
* Name of the client or device.
*/
name: string;
}

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.

let platformClient;

if (hasCachedPlatformClient) {
const platformClient = flPlatformAuthorizer.createPlaformClient(
cachedDeviceId,
cachedDeviceName,
);
savePlatformClient(platformClient);
} else {
platformClient = flPlatformAuthorizer.createPlaformClient();
}

Create Content Authorizer​

The @quickplay/content-authorization 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 delivery type for which authorization is required. The delivery type is streaming upon successful authorization, PlatformAsset is obtained, which could be used to play with our Player.

// Content Authorizer creation
const contentAuthconfiguration = {
endPointUrl: contentAuthEndPoint
clientRegistrationEndPointUrl: deviceRegistrationEndPoint,
};

const contentAuthorizer = flContentAuthorization.createContentAuthorizer(
contentAuthconfiguration,
platformAuthorizer,
platformClient);

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.

warning

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 for an Asset​

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 | Playready
  • Catalog Type: movie | tvepisode | shortvideo | sportshow | sporthighlight | sportclip | sportevent | sportsliveevent | channel | event
  • Content Type: VOD | Live
// create asset
const asset = contentAuthorizer.authorizePlayback({
mediaID: platformcontentId.value,
consumptionType: flContentAuthorization.ConsumptionType.VOD,
catalogType: 'movie',
mediaType: flPlayerInterface.MediaType.DASH,
drmScheme: flPlayerInterface.DrmScheme.WIDEVINE,
});

Playback Ad Controls​

Set disablePreroll, disableCsai, or disableSsai on the PlatformAsset to control the corresponding ads in the playback authorization request. disablePreroll applies to live preroll and defaults to false. The request sends all three flags as strings, either "true" or "false".

const asset = contentAuthorizer.authorizePlayback({
mediaID: platformcontentId.value,
consumptionType: flContentAuthorization.ConsumptionType.LIVE,
catalogType: 'channel',
mediaType: flPlayerInterface.MediaType.DASH,
drmScheme: flPlayerInterface.DrmScheme.WIDEVINE,
disablePreroll: true,
});

Free Preview​

Set freePreview to true and specify fpMode ('full' or 'light') on the PlatformAsset to request a preview session. Refer to Free Preview for full configuration, heartbeat integration, and event-handling guidelines.

Prefetch Content​

Set preload to true on the PlatformAsset when you authorize content ahead of playback, for example to prepare the next item in a rail before the viewer selects it. The request sends preload as a JSON boolean and omits it when you don't set it.

Playback authorization doesn't reserve a stream concurrency slot for a preload request. Configure Heartbeat to reserve the slot when the player loads the content; refer to Reserve Stream on Player Load. If you skip this step, the prefetched session plays without a reserved slot until the viewer pauses and resumes.

const contentAuthorizationData = await contentAuthorizer.authorizePlayback({
mediaID: platformcontentId.value,
consumptionType: flContentAuthorization.ConsumptionType.VOD,
catalogType: 'movie',
mediaType: flPlayerInterface.MediaType.DASH,
drmScheme: flPlayerInterface.DrmScheme.WIDEVINE,
preload: true,
});
note

preload requires Web SDK 7.1.294 or later. Stream reservation on player load requires 7.1.297 or later. Don't set preload on the platformAsset of a CastAsset: the cast receiver doesn't reserve a stream on load.

Audio and Player Preferences​

Pass an optional audioLanguage on PlatformAsset (for example, 'TAM') to include the preferred audio language in the playback authorization request.

The playback authorization response includes optional upfrontAudio, preference, and audioLanguages fields. The SDK exposes these values; your app controls the audio picker and track selection.

  • Show your audio picker when upfrontAudio is true.
  • When preference.audio.lang is present, use it as the preferred audio language. It replaces the removed userPreferredLanguage field.
  • Use audioLanguages to render available audio language options. Each entry follows the AudioLanguage shape:
interface AudioLanguage {
languageCode?: string;
label?: string;
active?: boolean;
}
const contentAuthorizationData = await contentAuthorizer.authorizePlayback({
mediaID: platformcontentId.value,
consumptionType: flContentAuthorization.ConsumptionType.LIVE,
catalogType: 'livesport',
mediaType: flPlayerInterface.MediaType.HLS,
drmScheme: flPlayerInterface.DrmScheme.WIDEVINE,
audioLanguage: 'TAM',
});

// contentAuthorizationData.audioLanguages:
// [{ languageCode: 'ENG', label: 'English', active: false }, { languageCode: 'TAM', label: 'Tamil', active: true }, ...]

preference follows the PlayerPreference shape:

interface PlayerPreference {
audio?: { lang?: string; kind?: string };
subtitle?: { enabled?: boolean; lang?: string; ty?: string };
video?: { quality?: string };
}

Your app manages saved preferences through the settings API, using the SDK's authorized request utility with a platform authorizer configured with the correct xClientId and user authorization delegate. For an episode, use its show ID (stl_id) as the item ID; for other titles, use the content ID.

warning

Saving replaces the complete player object, so include every preference you want to keep.

import { createRequestBuilder } from '@quickplay/foundation';
import { AuthorizationUtil } from '@quickplay/platform-authorizer';

const request = createRequestBuilder()
.url(settingsEndpoint)
.path('/user/setting/create')
.headers({ 'Content-Type': 'application/json' })
.put({ itemId: showId, player: { audio: { lang: 'HIN', kind: 'main' } } })
.build();
await AuthorizationUtil.makeAuthorizedRequest(request, platformAuthorizer);

Start Playback​

A Player instance could be created by supplying player builder properties like contentURL, mediaType, drmScheme, etc to PlayerBuilder class.

// Creating Player
const playerBuilder = flPlayer.createPlayerBuilder();

const playbackOptions = {
PlayOnLoad: true,
preferredAudioLanguage: 'fr',
preferredTextLanguage: 'fr',
networkRetries: 3,
networkTimeout: 40,
initialPlaybackTime: 0,
minBuffer: 30,
maxBuffer: 30,
bufferBehind: 40,
};

const player = playerBuilder
.mediaElement(videoElement)
.mediaUrl(asset.contentUrl)
.drmLicenseUrl(asset.licenseUrl)
.drmScheme(asset.drmScheme)
.playbackOptions(playbackOptions)
.build();

player.play();