Skip to content

Commit d4bb658

Browse files
committed
docs: update plugins section
1 parent e3a0afa commit d4bb658

File tree

1 file changed

+89
-24
lines changed

1 file changed

+89
-24
lines changed

docs/pages/other/plugin.md

Lines changed: 89 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,67 @@ npx create-react-native-library@latest react-native-video-custom-analytics
3434
Both Android and iOS implementations expose an `RNVPlugin` interface.
3535
Your `react-native-video-custom-analytics` package should implement this interface and register itself as a plugin for `react-native-video`.
3636

37+
## Plugin Types
38+
39+
There are two types of plugins you can implement:
40+
41+
1. **Base Plugin (`RNVPlugin`)**: For general-purpose plugins that don't need specific player implementation details.
42+
2. **Player-Specific Plugins**:
43+
- `RNVAVPlayerPlugin` for iOS: Provides type-safe access to AVPlayer instances
44+
- `RNVExoplayerPlugin` for Android: Provides type-safe access to ExoPlayer instances
45+
46+
Choose the appropriate plugin type based on your needs. If you need direct access to player-specific APIs, use the player-specific plugin classes.
47+
3748
## Android Implementation
3849

3950
### 1. Create the Plugin
4051

41-
First, instantiate a class that extends `RNVPlugin`.
52+
You can implement either the base `RNVPlugin` interface or the player-specific `RNVExoplayerPlugin` interface.
53+
54+
#### Base Plugin
55+
56+
```kotlin
57+
class MyAnalyticsPlugin : RNVPlugin {
58+
override fun onInstanceCreated(id: String, player: Any) {
59+
// Handle player creation
60+
}
61+
62+
override fun onInstanceRemoved(id: String, player: Any) {
63+
// Handle player removal
64+
}
65+
}
66+
```
67+
68+
#### ExoPlayer-Specific Plugin
4269

43-
The recommended approach is to implement `RNVPlugin` inside the Module file (`VideoPluginSampleModule`).
70+
```kotlin
71+
class MyExoPlayerAnalyticsPlugin : RNVExoplayerPlugin {
72+
override fun onInstanceCreated(id: String, player: ExoPlayer) {
73+
// Handle ExoPlayer creation with type-safe access
74+
}
75+
76+
override fun onInstanceRemoved(id: String, player: ExoPlayer) {
77+
// Handle ExoPlayer removal with type-safe access
78+
}
79+
}
80+
```
4481

4582
The `RNVPlugin` interface defines two functions:
4683

4784
```kotlin
4885
/**
49-
* Called when a new player instance is created.
50-
* @param id: A unique identifier for the player instance.
51-
* @param player: The instantiated player reference.
86+
* Function called when a new player is created
87+
* @param id: a random string identifying the player
88+
* @param player: the instantiated player reference
5289
*/
5390
fun onInstanceCreated(id: String, player: Any)
5491

5592
/**
56-
* Called when a player instance should be destroyed.
57-
* The plugin should free resources and release all references to the player object.
58-
* @param id: A unique identifier for the player instance.
59-
* @param player: The player to release.
93+
* Function called when a player should be destroyed
94+
* when this callback is called, the plugin shall free all
95+
* resources and release all reference to Player object
96+
* @param id: a random string identifying the player
97+
* @param player: the player to release
6098
*/
6199
fun onInstanceRemoved(id: String, player: Any)
62100
```
@@ -65,8 +103,6 @@ fun onInstanceRemoved(id: String, player: Any)
65103

66104
To register the plugin within the main `react-native-video` package, call:
67105

68-
To register your plugin with the main react native video package, call the following function:
69-
70106
```kotlin
71107
ReactNativeVideoManager.getInstance().registerPlugin(plugin)
72108
```
@@ -87,25 +123,54 @@ s.dependency "react-native-video"
87123

88124
### 2. Create the Plugin
89125

90-
Instantiate a class that extends `RNVPlugin`.
126+
You can implement either the base `RNVPlugin` class or the player-specific `RNVAVPlayerPlugin` class.
91127

92-
The recommended approach is to implement `RNVPlugin` inside the entry point module file (`VideoPluginSample`).
128+
#### Base Plugin
93129

94-
The `RNVPlugin` interface defines two functions:
130+
```swift
131+
class MyAnalyticsPlugin: RNVPlugin {
132+
override func onInstanceCreated(id: String, player: Any) {
133+
// Handle player creation
134+
}
135+
136+
override func onInstanceRemoved(id: String, player: Any) {
137+
// Handle player removal
138+
}
139+
}
140+
```
141+
142+
#### AVPlayer-Specific Plugin
143+
144+
```swift
145+
class MyAVPlayerAnalyticsPlugin: RNVAVPlayerPlugin {
146+
override func onInstanceCreated(id: String, player: AVPlayer) {
147+
// Handle AVPlayer creation with type-safe access
148+
}
149+
150+
override func onInstanceRemoved(id: String, player: AVPlayer) {
151+
// Handle AVPlayer removal with type-safe access
152+
}
153+
}
154+
```
155+
156+
The `RNVPlugin` class defines two methods:
95157

96158
```swift
97159
/**
98-
* Called when a new player instance is created.
99-
* @param player: The instantiated player reference.
160+
* Function called when a new player is created
161+
* @param id: a random string identifying the player
162+
* @param player: the instantiated player reference
100163
*/
101-
func onInstanceCreated(player: Any)
164+
open func onInstanceCreated(id: String, player: Any) { /* no-op */ }
102165

103166
/**
104-
* Called when a player instance should be destroyed.
105-
* The plugin should free resources and release all references to the player object.
106-
* @param player: The player to release.
167+
* Function called when a player should be destroyed
168+
* when this callback is called, the plugin shall free all
169+
* resources and release all reference to Player object
170+
* @param id: a random string identifying the player
171+
* @param player: the player to release
107172
*/
108-
func onInstanceRemoved(player: Any)
173+
open func onInstanceRemoved(id: String, player: Any) { /* no-op */ }
109174
```
110175

111176
### 3. Register the Plugin
@@ -154,7 +219,7 @@ class CustomDRMManager : DRMManagerSpec {
154219

155220
#### 2/ Register DRM manager in your plugin
156221

157-
Implement `getDRMManager()` in your plugin to provide the custom DRM manager:
222+
Implement `getDRMManager()` in your ExoPlayer plugin to provide the custom DRM manager:
158223

159224
```kotlin
160225
class CustomVideoPlugin : RNVExoplayerPlugin {
@@ -216,12 +281,12 @@ class CustomDRMManager: NSObject, DRMManagerSpec {
216281

217282
#### 2/ Register DRM manager in your plugin
218283

219-
Implement `getDRMManager()` in your plugin to provide the custom DRM manager:
284+
Implement `getDRMManager()` in your AVPlayer plugin to provide the custom DRM manager:
220285

221286
```swift
222287
class CustomVideoPlugin: RNVAVPlayerPlugin {
223288
override func getDRMManager() -> DRMManagerSpec? {
224-
return CustomDRMManager.self
289+
return CustomDRMManager()
225290
}
226291

227292
override func onInstanceCreated(id: String, player: AVPlayer) {

0 commit comments

Comments
 (0)