What Are Plugins?
Plugins are modular extensions that hook into the video player’s lifecycle and processing pipeline. They enable you to extend React Native Video functionality without modifying the core library.Key Capabilities
Source Customization
Modify video sources before playback - add headers, transform URLs, or apply CDN logic
DRM Integration
Implement custom DRM solutions for Widevine, FairPlay, or proprietary systems
Media Factory Override
Customize ExoPlayer components on Android for advanced playback control
Lifecycle Hooks
React to player and view creation/destruction for analytics and resource management
Architecture Overview
The plugin system is built on three core components:Core Components
| Component | Description |
|---|---|
| PluginsRegistry | Singleton that manages plugin registration and coordinates interactions |
| ReactNativeVideoPluginSpec | Interface/protocol defining the plugin contract |
| ReactNativeVideoPlugin | Base class with default implementations for easy plugin creation |
How It Works
- Registration: Plugins register with the
PluginsRegistrysingleton - Coordination: The registry notifies all plugins of lifecycle events
- Processing: Plugins process sources and provide DRM managers in registration order
- Execution: The video player uses the modified sources and custom components
Plugin Lifecycle
Plugins receive notifications for key events throughout the player lifecycle:Player Creation
onPlayerCreated is called when a new player instance is initialized. Use this to set up player-specific resources or event listeners.View Creation
onVideoViewCreated is called when the video view component is mounted. Configure UI-specific settings here.Source Processing
overrideSource is called before playback starts. Modify headers, URLs, or other source properties.DRM Resolution
getDRMManager is called when DRM-protected content is detected. Return a DRM manager if your plugin handles the DRM type.Platform Support
Platform Differences
| Feature | Android (ExoPlayer) | iOS (AVFoundation) |
|---|---|---|
| Underlying Player | ExoPlayer (Media3) | AVFoundation |
| Media Factory Customization | ✅ Extensive | ⚠️ Limited |
| Cache Control | ✅ Supported | ❌ Not Available |
| Method Style | Synchronous | Async/await |
| Memory Management | Manual cleanup required | Automatic in deinit |
Android-Specific Features
Android plugins can override ExoPlayer components:- Media Data Source Factory - Custom network handling and caching
- Media Source Factory - Custom media format support
- Media Item Builder - Add metadata, subtitles, DRM configuration
- Cache Control - Per-source caching policies
iOS-Specific Features
iOS plugins work with AVFoundation:- Async/await - All plugin methods support asynchronous operations
- Automatic Cleanup - Plugins auto-unregister in
deinit - FairPlay DRM - Native support for Apple’s DRM system
Quick Start Example
Android Plugin
iOS Plugin
Plugin Registration
Automatic Registration
TheReactNativeVideoPlugin base class automatically registers your plugin:
Manual Registration
ImplementReactNativeVideoPluginSpec for full control:
Plugin Ordering
Plugins are processed in registration order. Later plugins can see and modify changes made by earlier plugins.
Source Processing Chain
DRM Manager Resolution
The first plugin to return a non-null DRM manager wins:Memory Management
Weak References
Plugins receive weak references to prevent retain cycles:Plugin Cleanup
- Android
- iOS
Available Plugins
DRM Plugin
Official DRM plugin supporting Widevine (Android) and FairPlay (iOS/visionOS)
Create Custom Plugin
Learn how to build your own plugins for custom functionality
Use Cases
Common Plugin Scenarios
- Authentication - Add bearer tokens to video requests
- CDN Management - Route videos through optimal CDN endpoints
- Analytics - Track playback events and performance metrics
- Content Protection - Implement DRM for Widevine, FairPlay, or custom systems
- Quality Control - Force specific bitrates or resolutions
- Caching - Implement custom caching strategies
- A/B Testing - Switch between video sources for experimentation
Best Practices
Keep Plugins Focused
Keep Plugins Focused
Each plugin should have a single, well-defined responsibility. Don’t create “god plugins” that do everything.
Check Weak References
Check Weak References
Always verify weak references aren’t null before accessing. Players and views may be destroyed at any time.
Minimize Synchronous Work
Minimize Synchronous Work
Plugin methods are called during critical paths. Keep processing fast and defer heavy operations.
Handle Errors Gracefully
Handle Errors Gracefully
Don’t throw exceptions from plugin methods unless absolutely necessary. Log errors and fail gracefully.
Clean Up Resources
Clean Up Resources
Always unregister plugins when done (especially on Android). Remove listeners and release resources.
Document Plugin Dependencies
Document Plugin Dependencies
If your plugin depends on specific player configuration or other plugins, document these requirements.
Next Steps
DRM Plugin
Learn about the official DRM plugin
Creating Plugins
Build your own custom plugins
Plugin Interface
Full API reference for plugin methods