DRM Configuration

Learn how to configure Digital Rights Management (DRM) protection for your content with IAppPlayer.

DRM Overview

IAppPlayer supports multiple DRM systems to protect your premium content. The supported DRM types vary by platform:

DRM Type Description Supported Platforms
widevine Google Widevine Android
fairplay Apple FairPlay iOS
clearkey W3C ClearKey Android
token Token-based DRM Universal

IAppPlayerDrmConfiguration

The DRM configuration object contains all necessary parameters for setting up content protection:

Parameter Type Description Platform
drmType IAppPlayerDrmType? DRM type Universal
token String? DRM token Universal
licenseUrl String? License server URL Universal
certificateUrl String? Certificate URL iOS (FairPlay)
headers Map<String, String>? DRM request headers Universal
clearKey String? ClearKey configuration (JSON string) Android

Widevine DRM (Android)

Widevine is Google's DRM solution, widely used for Android devices. It supports multiple security levels (L1, L2, L3).

Basic Example

dart
// Widevine DRM (Android)
drmConfiguration: IAppPlayerDrmConfiguration(
  drmType: IAppPlayerDrmType.widevine,
  licenseUrl: 'https://widevine-license.server.com/license',
  headers: {
    'Authorization': 'Bearer token',
    'Content-Type': 'application/octet-stream',
  },
),
Note: Widevine DRM requires L1 or L3 support

FairPlay DRM (iOS)

FairPlay is Apple's DRM solution for iOS devices. It requires both a certificate and license server.

Basic Example

dart
// FairPlay DRM (iOS)
drmConfiguration: IAppPlayerDrmConfiguration(
  drmType: IAppPlayerDrmType.fairplay,
  certificateUrl: 'https://fairplay.server.com/certificate',
  licenseUrl: 'https://fairplay.server.com/license',
  headers: {
    'Authorization': 'Bearer token',
  },
),
Tip: Requires certificate URL configuration. Some implementations may force L3 security level. Requires proper license server configuration

ClearKey DRM

ClearKey is an open standard DRM system that uses clear text keys. It's useful for testing and basic content protection.

Basic Example

dart
// ClearKey DRM (Android)
drmConfiguration: IAppPlayerDrmConfiguration(
  drmType: IAppPlayerDrmType.clearkey,
  clearKey: '{"keys":[{"kty":"oct","k":"GawgguFyGrWKav7AX4VKUg","kid":"nrQFDeRLSAKTLifXUIPiZg"}]}',
),

ClearKey Generation Steps (Android only)

  1. Create `drm_file.xml` configuration file
  2. Generate encrypted file using MP4Box:
    MP4Box -crypt drm_file.xml input.mp4 -out encrypted_tmp.mp4
    MP4Box -frag 240000 encrypted_tmp.mp4 -out encrypted.mp4

Token-based DRM

Token-based DRM provides a simple authentication mechanism for content protection.

dart
final result = await IAppPlayerConfig.createPlayer(
  url: 'https://example.com/token_protected.m3u8',
  drmConfiguration: IAppPlayerDrmConfiguration(
    drmType: IAppPlayerDrmType.token,
    token: 'your-access-token',
  ),
  // Also include token in headers if needed
  headers: {
    'Authorization': 'Bearer your-access-token',
  },
  eventListener: (event) {},
);

Complete Examples

DRM Configuration Complete Example

dart
// Widevine DRM (Android)
drmConfiguration: IAppPlayerDrmConfiguration(
  drmType: IAppPlayerDrmType.widevine,
  licenseUrl: 'https://widevine-license.server.com/license',
  headers: {
    'Authorization': 'Bearer token',
    'Content-Type': 'application/octet-stream',
  },
),

// FairPlay DRM (iOS)
drmConfiguration: IAppPlayerDrmConfiguration(
  drmType: IAppPlayerDrmType.fairplay,
  certificateUrl: 'https://fairplay.server.com/certificate',
  licenseUrl: 'https://fairplay.server.com/license',
  headers: {
    'Authorization': 'Bearer token',
  },
),

// ClearKey DRM (Android)
drmConfiguration: IAppPlayerDrmConfiguration(
  drmType: IAppPlayerDrmType.clearkey,
  clearKey: '{"keys":[{"kty":"oct","k":"GawgguFyGrWKav7AX4VKUg","kid":"nrQFDeRLSAKTLifXUIPiZg"}]}',
),

Troubleshooting

Check the following:

  • Verify license server URL is correct
  • Ensure authentication headers are valid
  • Check network connectivity
  • Verify DRM token hasn't expired

Common causes:

  • Device doesn't support required security level
  • Rooted/jailbroken devices may be blocked
  • HDCP requirements not met
  • Device limit exceeded

For ClearKey:

  • Ensure JSON format is valid
  • Base64 encode keys properly
  • Check key ID matches content

Best Practices

  • Always use HTTPS for DRM-protected content
  • Implement token refresh mechanism
  • Handle DRM errors gracefully with user feedback
  • Test on various devices with different security levels
  • Monitor license server response times