@react-native-video/drm package provides official DRM (Digital Rights Management) support for React Native Video through the plugin system. It enables playback of protected content using Widevine on Android and FairPlay on iOS/visionOS.
Overview
The DRM plugin integrates seamlessly with React Native Video’s plugin architecture to provide:- Widevine DRM for Android via ExoPlayer
- FairPlay DRM for iOS and visionOS via AVFoundation
- Simple API - Enable once, configure per-source
- Nitro Modules - High-performance native integration
- Automatic registration - No manual native code changes required
Installation
Requirements
- react-native-video >= 7.0.0-alpha.3
- react-native-nitro-modules >= 0.27.2
- React Native >= 0.70
Expo Support
The DRM plugin uses Nitro Modules and requires native code compilation. Use a prebuild workflow - pure managed Expo apps are not supported.
Quick Start
Enable the plugin once at app startup, then pass DRM configuration to your video sources.API Reference
Plugin Methods
Imported from@react-native-video/drm:
enable()
Registers the DRM plugin with React Native Video.
Android requires calling
enable() before playing DRM content. iOS attempts auto-enable but calling is safe and recommended.disable()
Unregisters the DRM plugin.
isEnabled
Boolean indicating current plugin registration status.
DRM Configuration
Pass these options via thedrm property in useVideoPlayer() or Video component:
Common Options
| Property | Type | Description |
|---|---|---|
type | 'widevine' | 'fairplay' | string | DRM system type. Defaults: Android → widevine, iOS/visionOS → fairplay |
licenseUrl | string | License server URL (required for default flows) |
Android-Specific (Widevine)
| Property | Type | Description |
|---|---|---|
licenseHeaders | Record<string, string> | Custom headers for license requests |
multiSession | boolean | Allow multiple DRM sessions (default: false) |
iOS-Specific (FairPlay)
| Property | Type | Description |
|---|---|---|
certificateUrl | string | FairPlay application certificate URL (required) |
contentId | string | Content identifier. Auto-inferred from skd:// URL if not provided |
getLicense | (payload) => Promise<string> | Custom license fetch function (advanced) |
Platform-Specific Guides
Android (Widevine)
Widevine DRM is handled through ExoPlayer’s Media3 framework. Example: Widevine with Custom HeadersiOS (FairPlay)
FairPlay DRM uses Apple’s AVFoundation framework and requires an application certificate. Example: FairPlay with Default FlowvisionOS (FairPlay)
FairPlay works the same on visionOS as iOS:Advanced Usage
Platform-Specific DRM Configuration
Conditional DRM Enable
Troubleshooting
Failed to fetch certificate (iOS)
Failed to fetch certificate (iOS)
Symptoms: Error loading FairPlay certificateSolutions:
- Verify
certificateUrlis accessible and returns valid.ceror.derfile - Check network connectivity and SSL certificates
- Ensure the URL uses HTTPS
- Test the URL in a browser or with curl:
Failed to fetch license
Failed to fetch license
Symptoms: Video loads but playback fails with license errorSolutions:
- iOS: Check that
source.headersincludes required authorization. The default flow uses these headers for license requests. - Android: Verify
licenseHeaderscontains all required headers - Confirm
licenseUrlis correct and accessible - Test license server with curl or Postman
- Check server logs for authentication or format errors
DRM not working on iOS Simulator
DRM not working on iOS Simulator
Symptoms: DRM playback fails on simulator but no errors shownSolution:
FairPlay is not supported on the iOS Simulator. This is an Apple limitation. Always test DRM on physical devices:
Unsupported DRM type error
Unsupported DRM type error
Symptoms: Error: “Unsupported DRM type”Solutions:
- Set
drm.typeto'widevine'(Android) or'fairplay'(iOS) - Or omit
typeto use platform defaults - Ensure you’re not trying to use Widevine on iOS or FairPlay on Android
Plugin not found / enable() has no effect
Plugin not found / enable() has no effect
Symptoms: DRM doesn’t work even after calling
enable()Solutions:- Ensure
@react-native-video/drmis installed:npm ls @react-native-video/drm - Rebuild the app after installation (don’t just reload)
- Check that
react-native-nitro-modules>= 0.27.2 is installed - On iOS, run
npx pod-installafter installing - Clear build caches:
Multi-session DRM issues (Android)
Multi-session DRM issues (Android)
Symptoms: Multiple DRM videos fail to play simultaneouslySolution:
Enable multi-session support:
Implementation Details
The DRM plugin is implemented as a native plugin on both platforms:Android Implementation
DRMManager that integrates with ExoPlayer’s MediaDrm API for Widevine license acquisition.
iOS Implementation
DRMManager that implements AVContentKeySessionDelegate for FairPlay license handling.
Nitro Modules Bridge
The JavaScript API uses Nitro Modules for high-performance native communication:Best Practices
Enable Early
Call
enable() in your app’s entry point (App.tsx or index.js) before any video playbackTest on Devices
Always test DRM on physical devices - simulators don’t support FairPlay
Secure Credentials
Never hardcode license server credentials. Use secure storage or environment variables
Handle Errors
Implement proper error handling for license acquisition failures
Resources
- GitHub Repository
- Plugin Architecture Overview
- Creating Custom Plugins
- Widevine Documentation
- FairPlay Streaming Documentation