DrmParams
Configuration for Digital Rights Management (DRM) when playing protected video content.
interface DrmParams {
licenseUrl?: string;
certificateUrl?: string;
contentId?: string;
type?: DRMType;
licenseHeaders?: Record<string, string>;
multiSession?: boolean;
getLicense?: (payload: OnGetLicensePayload) => Promise<string>;
}
Properties
The URL for the DRM license server.Platforms: Android, iOS, visionOSlicenseUrl: 'https://drm.example.com/license'
The URL for the DRM certificate (FairPlay only).Platforms: iOS, visionOScertificateUrl: 'https://drm.example.com/certificate'
Unique identifier for the protected content (FairPlay only).Platforms: iOS, visionOScontentId: 'content-id-123'
The DRM system to use.Platforms: Android, iOS, visionOSPossible values:
'widevine' - Widevine DRM (Android)
'fairplay' - FairPlay DRM (iOS/visionOS)
- Custom string for other DRM systems
type: 'widevine' // Android
type: 'fairplay' // iOS
Custom HTTP headers to send with the license request.Platforms: Android, iOS, visionOSlicenseHeaders: {
'Authorization': 'Bearer token123',
'X-Custom-Header': 'value'
}
Whether to allow multiple DRM sessions simultaneously.Platforms: Android only
getLicense
(payload: OnGetLicensePayload) => Promise<string>
Custom function to retrieve the license. Useful for implementing custom license acquisition logic.Platforms: iOS onlyThe function receives an OnGetLicensePayload object and must return a Promise that resolves to the license string.getLicense: async (payload) => {
const response = await fetch(payload.licenseUrl, {
method: 'POST',
body: payload.spc,
headers: {
'Content-Type': 'application/octet-stream'
}
});
return await response.text();
}
OnGetLicensePayload
Payload object passed to the getLicense function:
interface OnGetLicensePayload {
contentId: string;
licenseUrl: string;
keyUrl: string;
spc: string;
}
The content ID for the DRM license request. Unique identifier for the content being played.
The license URL for the DRM license request.
The key URL for the DRM license request. Typically starts with skd:// or clearkey://.
The Secure Playback Context (SPC) for the DRM license request. Base64-encoded string containing information about the playback environment.
DRMType
type DRMType = 'widevine' | 'fairplay' | (string & {});
Supported DRM types:
'widevine' - Google Widevine (Android)
'fairplay' - Apple FairPlay (iOS/visionOS)
- Custom string for other DRM systems
Examples
Widevine DRM (Android)
import { VideoConfig } from 'react-native-video';
const config: VideoConfig = {
uri: 'https://example.com/protected-video.mpd',
drm: {
type: 'widevine',
licenseUrl: 'https://drm.example.com/widevine/license',
licenseHeaders: {
'Authorization': 'Bearer token123'
}
}
};
FairPlay DRM (iOS)
import { VideoConfig } from 'react-native-video';
const config: VideoConfig = {
uri: 'https://example.com/protected-video.m3u8',
drm: {
type: 'fairplay',
licenseUrl: 'https://drm.example.com/fairplay/license',
certificateUrl: 'https://drm.example.com/fairplay/certificate',
contentId: 'content-123'
}
};
Custom License Acquisition (iOS)
import { VideoConfig, OnGetLicensePayload } from 'react-native-video';
const customGetLicense = async (payload: OnGetLicensePayload): Promise<string> => {
// Custom license acquisition logic
const response = await fetch(payload.licenseUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/octet-stream',
'Authorization': 'Bearer custom-token'
},
body: payload.spc
});
if (!response.ok) {
throw new Error('Failed to acquire license');
}
return await response.text();
};
const config: VideoConfig = {
uri: 'https://example.com/protected-video.m3u8',
drm: {
type: 'fairplay',
licenseUrl: 'https://drm.example.com/license',
certificateUrl: 'https://drm.example.com/certificate',
contentId: 'content-123',
getLicense: customGetLicense
}
};
Multi-Session DRM (Android)
import { VideoConfig } from 'react-native-video';
const config: VideoConfig = {
uri: 'https://example.com/protected-video.mpd',
drm: {
type: 'widevine',
licenseUrl: 'https://drm.example.com/license',
multiSession: true // Allow multiple concurrent DRM sessions
}
};
| Property | Android | iOS | visionOS | tvOS |
|---|
licenseUrl | ✓ | ✓ | ✓ | ✓ |
certificateUrl | - | ✓ | ✓ | ✓ |
contentId | - | ✓ | ✓ | ✓ |
type | ✓ | ✓ | ✓ | ✓ |
licenseHeaders | ✓ | ✓ | ✓ | ✓ |
multiSession | ✓ | - | - | - |
getLicense | - | ✓ | ✓ | ✓ |
- VideoConfig - Main video configuration type that includes DRM parameters