-
Notifications
You must be signed in to change notification settings - Fork 3k
Expand file tree
/
Copy pathVideoPluginSampleModule.kt
More file actions
45 lines (36 loc) · 1.35 KB
/
VideoPluginSampleModule.kt
File metadata and controls
45 lines (36 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.videopluginsample
import androidx.media3.common.PlaybackException
import androidx.media3.common.Player
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.util.EventLogger
import com.brentvatne.common.toolbox.DebugLog
import com.brentvatne.exoplayer.RNVExoplayerPlugin
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
class VideoPluginSampleModule(reactContext: ReactApplicationContext) :
ReactContextBaseJavaModule(reactContext), RNVExoplayerPlugin, Player.Listener {
private val debugEventLogger = EventLogger("RNVPluginSample")
override fun getName(): String {
return NAME
}
@ReactMethod
fun setMetadata(promise: Promise) {
promise.resolve(true)
}
companion object {
const val NAME = "VideoPluginSample"
const val TAG = "VideoPluginSampleModule"
}
override fun onPlayerError(error: PlaybackException) {
DebugLog.e(TAG, "onPlayerError: " + error.errorCodeName)
}
override fun onInstanceCreated(id: String, player: ExoPlayer) {
player.addAnalyticsListener(debugEventLogger)
player.addListener(this)
}
override fun onInstanceRemoved(id: String, player: ExoPlayer) {
player.removeAnalyticsListener(debugEventLogger)
}
}