react-native-theoplayer 11.6.0 → 11.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (254) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +69 -0
  3. package/android/build.gradle +3 -2
  4. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  5. package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
  6. package/android/gradlew +176 -110
  7. package/android/gradlew.bat +23 -18
  8. package/android/src/main/java/com/theoplayer/PlayerConfigAdapter.kt +6 -0
  9. package/android/src/main/java/com/theoplayer/PlayerEventEmitter.kt +2 -2
  10. package/android/src/main/java/com/theoplayer/ReactTHEOplayerContext.kt +37 -8
  11. package/android/src/main/java/com/theoplayer/ReactTHEOplayerPackage.kt +3 -0
  12. package/android/src/main/java/com/theoplayer/ReactTHEOplayerView.kt +51 -3
  13. package/android/src/main/java/com/theoplayer/ads/AdEventAdapter.kt +4 -0
  14. package/android/src/main/java/com/theoplayer/ads/AdsModule.kt +6 -6
  15. package/android/src/main/java/com/theoplayer/drm/ContentProtectionAdapter.kt +17 -5
  16. package/android/src/main/java/com/theoplayer/drm/ContentProtectionModule.kt +61 -7
  17. package/android/src/main/java/com/theoplayer/drm/ProxyContentProtectionIntegration.kt +12 -5
  18. package/android/src/main/java/com/theoplayer/drm/ProxyContentProtectionIntegrationFactory.kt +3 -1
  19. package/android/src/main/java/com/theoplayer/integration/Integration.kt +72 -0
  20. package/android/src/main/java/com/theoplayer/integration/IntegrationRegistration.kt +68 -0
  21. package/android/src/main/java/com/theoplayer/integration/PlayerFacade.kt +187 -0
  22. package/android/src/main/java/com/theoplayer/integration/PlayerFacadeAdState.kt +19 -0
  23. package/android/src/main/java/com/theoplayer/integration/PlayerFacadeAds.kt +73 -0
  24. package/android/src/main/java/com/theoplayer/integration/PlayerFacadeAdsBridge.kt +112 -0
  25. package/android/src/main/java/com/theoplayer/integration/PlayerFacadeEventSubscription.kt +11 -0
  26. package/android/src/main/java/com/theoplayer/integration/PlayerFacadeEvents.kt +139 -0
  27. package/android/src/main/java/com/theoplayer/metrics/MetricsModule.kt +37 -0
  28. package/android/src/main/java/com/theoplayer/theoads/THEOadsModule.kt +1 -1
  29. package/android/src/main/java/com/theoplayer/theolive/EndpointAdapter.kt +33 -0
  30. package/android/src/test/java/com/theoplayer/integration/PlayerFacadeAdsBridgeTest.kt +250 -0
  31. package/android/src/test/java/com/theoplayer/integration/PlayerFacadeConfigurationTest.kt +30 -0
  32. package/android/src/test/java/com/theoplayer/integration/PlayerFacadeTest.kt +507 -0
  33. package/android/src/test/java/com/theoplayer/integration/PlayerFacadeTestHost.kt +104 -0
  34. package/ios/THEOplayerRCTBridge.m +19 -0
  35. package/ios/THEOplayerRCTPlayerAPI.swift +31 -0
  36. package/ios/Theoplayer-Bridging-Header.h +0 -1
  37. package/ios/contentprotection/THEOplayerRCTContentProtectionAPI.swift +39 -9
  38. package/ios/contentprotection/THEOplayerRCTContentProtectionAggregator.swift +15 -11
  39. package/ios/contentprotection/THEOplayerRCTProxyContentProtectionIntegration.swift +12 -7
  40. package/ios/metrics/THEOplayerRCTMetricsAPI.swift +31 -0
  41. package/ios/theolive/THEOplayerRCTTHEOliveEventAdapter.swift +21 -0
  42. package/lib/commonjs/api/barrel.js +31 -20
  43. package/lib/commonjs/api/barrel.js.map +1 -1
  44. package/lib/commonjs/api/metrics/MetricsAPI.js +2 -0
  45. package/lib/commonjs/api/metrics/MetricsAPI.js.map +1 -0
  46. package/lib/commonjs/api/metrics/barrel.js +17 -0
  47. package/lib/commonjs/api/metrics/barrel.js.map +1 -0
  48. package/lib/commonjs/api/player/Integration.js +2 -0
  49. package/lib/commonjs/api/player/Integration.js.map +1 -0
  50. package/lib/commonjs/api/player/PlayerEventMap.js +1 -1
  51. package/lib/commonjs/api/player/THEOplayer.js.map +1 -1
  52. package/lib/commonjs/api/player/barrel.js +11 -0
  53. package/lib/commonjs/api/player/barrel.js.map +1 -1
  54. package/lib/commonjs/api/track/MediaTrack.js +16 -0
  55. package/lib/commonjs/api/track/MediaTrack.js.map +1 -1
  56. package/lib/commonjs/internal/THEOplayerView.js +2 -0
  57. package/lib/commonjs/internal/THEOplayerView.js.map +1 -1
  58. package/lib/commonjs/internal/THEOplayerView.web.js +3 -1
  59. package/lib/commonjs/internal/THEOplayerView.web.js.map +1 -1
  60. package/lib/commonjs/internal/adapter/DefaultNativePlayerState.js +1 -0
  61. package/lib/commonjs/internal/adapter/DefaultNativePlayerState.js.map +1 -1
  62. package/lib/commonjs/internal/adapter/THEOplayerAdapter.js +18 -0
  63. package/lib/commonjs/internal/adapter/THEOplayerAdapter.js.map +1 -1
  64. package/lib/commonjs/internal/adapter/THEOplayerWebAdapter.js +21 -4
  65. package/lib/commonjs/internal/adapter/THEOplayerWebAdapter.js.map +1 -1
  66. package/lib/commonjs/internal/adapter/WebEventForwarder.js +62 -11
  67. package/lib/commonjs/internal/adapter/WebEventForwarder.js.map +1 -1
  68. package/lib/commonjs/internal/adapter/metrics/MetricsNativeAdapter.js +18 -0
  69. package/lib/commonjs/internal/adapter/metrics/MetricsNativeAdapter.js.map +1 -0
  70. package/lib/commonjs/internal/adapter/metrics/MetricsWebAdapter.js +16 -0
  71. package/lib/commonjs/internal/adapter/metrics/MetricsWebAdapter.js.map +1 -0
  72. package/lib/commonjs/internal/adapter/web/IntegrationRegistration.js +6 -0
  73. package/lib/commonjs/internal/adapter/web/IntegrationRegistration.js.map +1 -0
  74. package/lib/commonjs/internal/adapter/web/PlayerFacade.js +258 -0
  75. package/lib/commonjs/internal/adapter/web/PlayerFacade.js.map +1 -0
  76. package/lib/commonjs/internal/adapter/web/PlayerFacadeAPI.js +6 -0
  77. package/lib/commonjs/internal/adapter/web/PlayerFacadeAPI.js.map +1 -0
  78. package/lib/commonjs/internal/adapter/web/PlayerFacadeAdsEvents.js +114 -0
  79. package/lib/commonjs/internal/adapter/web/PlayerFacadeAdsEvents.js.map +1 -0
  80. package/lib/commonjs/internal/adapter/web/PlayerFacadeIntegration.js +6 -0
  81. package/lib/commonjs/internal/adapter/web/PlayerFacadeIntegration.js.map +1 -0
  82. package/lib/commonjs/internal/adapter/web/PlayerFacadeTypes.js +6 -0
  83. package/lib/commonjs/internal/adapter/web/PlayerFacadeTypes.js.map +1 -0
  84. package/lib/commonjs/internal/drm/ContentProtectionRegistry.js +38 -12
  85. package/lib/commonjs/internal/drm/ContentProtectionRegistry.js.map +1 -1
  86. package/lib/commonjs/manifest.json +1 -1
  87. package/lib/commonjs/plugins/typedoc-platform-icons/package-lock.json +200 -58
  88. package/lib/commonjs/plugins/typedoc-platform-icons/package.json +1 -1
  89. package/lib/commonjs/plugins/typedoc-platform-icons/tsconfig.json +2 -1
  90. package/lib/module/api/barrel.js +1 -0
  91. package/lib/module/api/barrel.js.map +1 -1
  92. package/lib/module/api/metrics/MetricsAPI.js +2 -0
  93. package/lib/module/api/metrics/MetricsAPI.js.map +1 -0
  94. package/lib/module/api/metrics/barrel.js +4 -0
  95. package/lib/module/api/metrics/barrel.js.map +1 -0
  96. package/lib/module/api/player/Integration.js +2 -0
  97. package/lib/module/api/player/Integration.js.map +1 -0
  98. package/lib/module/api/player/PlayerEventMap.js +1 -1
  99. package/lib/module/api/player/THEOplayer.js.map +1 -1
  100. package/lib/module/api/player/barrel.js +1 -0
  101. package/lib/module/api/player/barrel.js.map +1 -1
  102. package/lib/module/api/track/MediaTrack.js +16 -0
  103. package/lib/module/api/track/MediaTrack.js.map +1 -1
  104. package/lib/module/internal/THEOplayerView.js +2 -0
  105. package/lib/module/internal/THEOplayerView.js.map +1 -1
  106. package/lib/module/internal/THEOplayerView.web.js +3 -1
  107. package/lib/module/internal/THEOplayerView.web.js.map +1 -1
  108. package/lib/module/internal/adapter/DefaultNativePlayerState.js +1 -0
  109. package/lib/module/internal/adapter/DefaultNativePlayerState.js.map +1 -1
  110. package/lib/module/internal/adapter/THEOplayerAdapter.js +18 -0
  111. package/lib/module/internal/adapter/THEOplayerAdapter.js.map +1 -1
  112. package/lib/module/internal/adapter/THEOplayerWebAdapter.js +21 -4
  113. package/lib/module/internal/adapter/THEOplayerWebAdapter.js.map +1 -1
  114. package/lib/module/internal/adapter/WebEventForwarder.js +62 -11
  115. package/lib/module/internal/adapter/WebEventForwarder.js.map +1 -1
  116. package/lib/module/internal/adapter/metrics/MetricsNativeAdapter.js +13 -0
  117. package/lib/module/internal/adapter/metrics/MetricsNativeAdapter.js.map +1 -0
  118. package/lib/module/internal/adapter/metrics/MetricsWebAdapter.js +11 -0
  119. package/lib/module/internal/adapter/metrics/MetricsWebAdapter.js.map +1 -0
  120. package/lib/module/internal/adapter/web/IntegrationRegistration.js +4 -0
  121. package/lib/module/internal/adapter/web/IntegrationRegistration.js.map +1 -0
  122. package/lib/module/internal/adapter/web/PlayerFacade.js +253 -0
  123. package/lib/module/internal/adapter/web/PlayerFacade.js.map +1 -0
  124. package/lib/module/internal/adapter/web/PlayerFacadeAPI.js +4 -0
  125. package/lib/module/internal/adapter/web/PlayerFacadeAPI.js.map +1 -0
  126. package/lib/module/internal/adapter/web/PlayerFacadeAdsEvents.js +109 -0
  127. package/lib/module/internal/adapter/web/PlayerFacadeAdsEvents.js.map +1 -0
  128. package/lib/module/internal/adapter/web/PlayerFacadeIntegration.js +4 -0
  129. package/lib/module/internal/adapter/web/PlayerFacadeIntegration.js.map +1 -0
  130. package/lib/module/internal/adapter/web/PlayerFacadeTypes.js +4 -0
  131. package/lib/module/internal/adapter/web/PlayerFacadeTypes.js.map +1 -0
  132. package/lib/module/internal/drm/ContentProtectionRegistry.js +38 -12
  133. package/lib/module/internal/drm/ContentProtectionRegistry.js.map +1 -1
  134. package/lib/module/manifest.json +1 -1
  135. package/lib/module/plugins/typedoc-platform-icons/package-lock.json +200 -58
  136. package/lib/module/plugins/typedoc-platform-icons/package.json +1 -1
  137. package/lib/module/plugins/typedoc-platform-icons/tsconfig.json +2 -1
  138. package/lib/typescript/__tests__/ContentProtectionRegistry.test.d.ts +2 -0
  139. package/lib/typescript/__tests__/ContentProtectionRegistry.test.d.ts.map +1 -0
  140. package/lib/typescript/__tests__/PlayerFacade.test.d.ts +2 -0
  141. package/lib/typescript/__tests__/PlayerFacade.test.d.ts.map +1 -0
  142. package/lib/typescript/__tests__/PlayerFacadeWebAdapter.test.d.ts +2 -0
  143. package/lib/typescript/__tests__/PlayerFacadeWebAdapter.test.d.ts.map +1 -0
  144. package/lib/typescript/__tests__/index.test.d.ts +13 -0
  145. package/lib/typescript/__tests__/index.test.d.ts.map +1 -1
  146. package/lib/typescript/api/THEOplayerView.d.ts +4 -0
  147. package/lib/typescript/api/THEOplayerView.d.ts.map +1 -1
  148. package/lib/typescript/api/barrel.d.ts +1 -0
  149. package/lib/typescript/api/barrel.d.ts.map +1 -1
  150. package/lib/typescript/api/config/PlayerConfiguration.d.ts +15 -0
  151. package/lib/typescript/api/config/PlayerConfiguration.d.ts.map +1 -1
  152. package/lib/typescript/api/error/ChromecastError.d.ts +2 -2
  153. package/lib/typescript/api/event/AdEvent.d.ts +1 -1
  154. package/lib/typescript/api/metrics/MetricsAPI.d.ts +21 -0
  155. package/lib/typescript/api/metrics/MetricsAPI.d.ts.map +1 -0
  156. package/lib/typescript/api/metrics/barrel.d.ts +2 -0
  157. package/lib/typescript/api/metrics/barrel.d.ts.map +1 -0
  158. package/lib/typescript/api/player/Integration.d.ts +88 -0
  159. package/lib/typescript/api/player/Integration.d.ts.map +1 -0
  160. package/lib/typescript/api/player/PlayerEventMap.d.ts +1 -1
  161. package/lib/typescript/api/player/THEOplayer.d.ts +19 -0
  162. package/lib/typescript/api/player/THEOplayer.d.ts.map +1 -1
  163. package/lib/typescript/api/player/barrel.d.ts +1 -0
  164. package/lib/typescript/api/player/barrel.d.ts.map +1 -1
  165. package/lib/typescript/api/theoads/interstitial/Interstitial.d.ts +1 -1
  166. package/lib/typescript/api/theolive/TheoLiveEndpoint.d.ts +23 -5
  167. package/lib/typescript/api/theolive/TheoLiveEndpoint.d.ts.map +1 -1
  168. package/lib/typescript/api/theolive/WebrtcOptions.d.ts +1 -1
  169. package/lib/typescript/api/track/MediaTrack.d.ts +21 -4
  170. package/lib/typescript/api/track/MediaTrack.d.ts.map +1 -1
  171. package/lib/typescript/internal/adapter/DefaultNativePlayerState.d.ts +1 -0
  172. package/lib/typescript/internal/adapter/DefaultNativePlayerState.d.ts.map +1 -1
  173. package/lib/typescript/internal/adapter/NativePlayerState.d.ts +1 -0
  174. package/lib/typescript/internal/adapter/NativePlayerState.d.ts.map +1 -1
  175. package/lib/typescript/internal/adapter/THEOplayerAdapter.d.ts +6 -1
  176. package/lib/typescript/internal/adapter/THEOplayerAdapter.d.ts.map +1 -1
  177. package/lib/typescript/internal/adapter/THEOplayerWebAdapter.d.ts +6 -1
  178. package/lib/typescript/internal/adapter/THEOplayerWebAdapter.d.ts.map +1 -1
  179. package/lib/typescript/internal/adapter/WebEventForwarder.d.ts +3 -0
  180. package/lib/typescript/internal/adapter/WebEventForwarder.d.ts.map +1 -1
  181. package/lib/typescript/internal/adapter/metrics/MetricsNativeAdapter.d.ts +7 -0
  182. package/lib/typescript/internal/adapter/metrics/MetricsNativeAdapter.d.ts.map +1 -0
  183. package/lib/typescript/internal/adapter/metrics/MetricsWebAdapter.d.ts +8 -0
  184. package/lib/typescript/internal/adapter/metrics/MetricsWebAdapter.d.ts.map +1 -0
  185. package/lib/typescript/internal/adapter/web/IntegrationRegistration.d.ts +53 -0
  186. package/lib/typescript/internal/adapter/web/IntegrationRegistration.d.ts.map +1 -0
  187. package/lib/typescript/internal/adapter/web/PlayerFacade.d.ts +26 -0
  188. package/lib/typescript/internal/adapter/web/PlayerFacade.d.ts.map +1 -0
  189. package/lib/typescript/internal/adapter/web/PlayerFacadeAPI.d.ts +33 -0
  190. package/lib/typescript/internal/adapter/web/PlayerFacadeAPI.d.ts.map +1 -0
  191. package/lib/typescript/internal/adapter/web/PlayerFacadeAdsEvents.d.ts +21 -0
  192. package/lib/typescript/internal/adapter/web/PlayerFacadeAdsEvents.d.ts.map +1 -0
  193. package/lib/typescript/internal/adapter/web/PlayerFacadeIntegration.d.ts +43 -0
  194. package/lib/typescript/internal/adapter/web/PlayerFacadeIntegration.d.ts.map +1 -0
  195. package/lib/typescript/internal/adapter/web/PlayerFacadeTypes.d.ts +13 -0
  196. package/lib/typescript/internal/adapter/web/PlayerFacadeTypes.d.ts.map +1 -0
  197. package/lib/typescript/internal/drm/ContentProtectionRegistry.d.ts +3 -1
  198. package/lib/typescript/internal/drm/ContentProtectionRegistry.d.ts.map +1 -1
  199. package/lib/typescript/internal/drm/NativeContentProtectionEvent.d.ts +5 -0
  200. package/lib/typescript/internal/drm/NativeContentProtectionEvent.d.ts.map +1 -1
  201. package/package.json +5 -6
  202. package/react-native-theoplayer.podspec +7 -7
  203. package/src/__tests__/ContentProtectionRegistry.test.ts +239 -0
  204. package/src/__tests__/PlayerFacade.test.ts +579 -0
  205. package/src/__tests__/PlayerFacadeWebAdapter.test.ts +193 -0
  206. package/src/__tests__/index.test.tsx +15 -1
  207. package/src/api/THEOplayerView.ts +5 -0
  208. package/src/api/barrel.ts +1 -0
  209. package/src/api/config/PlayerConfiguration.ts +16 -0
  210. package/src/api/error/ChromecastError.ts +2 -2
  211. package/src/api/event/AdEvent.ts +1 -1
  212. package/src/api/metrics/MetricsAPI.ts +20 -0
  213. package/src/api/metrics/barrel.ts +1 -0
  214. package/src/api/player/Integration.ts +97 -0
  215. package/src/api/player/PlayerEventMap.ts +1 -1
  216. package/src/api/player/THEOplayer.ts +21 -0
  217. package/src/api/player/barrel.ts +1 -0
  218. package/src/api/theoads/interstitial/Interstitial.ts +1 -1
  219. package/src/api/theolive/TheoLiveEndpoint.ts +24 -5
  220. package/src/api/theolive/WebrtcOptions.ts +1 -1
  221. package/src/api/track/MediaTrack.ts +21 -4
  222. package/src/internal/THEOplayerView.tsx +2 -2
  223. package/src/internal/THEOplayerView.web.tsx +2 -2
  224. package/src/internal/adapter/DefaultNativePlayerState.ts +1 -0
  225. package/src/internal/adapter/NativePlayerState.ts +1 -0
  226. package/src/internal/adapter/THEOplayerAdapter.ts +24 -0
  227. package/src/internal/adapter/THEOplayerWebAdapter.ts +27 -4
  228. package/src/internal/adapter/WebEventForwarder.ts +74 -13
  229. package/src/internal/adapter/metrics/MetricsNativeAdapter.ts +12 -0
  230. package/src/internal/adapter/metrics/MetricsWebAdapter.ts +14 -0
  231. package/src/internal/adapter/web/IntegrationRegistration.ts +57 -0
  232. package/src/internal/adapter/web/PlayerFacade.ts +281 -0
  233. package/src/internal/adapter/web/PlayerFacadeAPI.ts +35 -0
  234. package/src/internal/adapter/web/PlayerFacadeAdsEvents.ts +119 -0
  235. package/src/internal/adapter/web/PlayerFacadeIntegration.ts +45 -0
  236. package/src/internal/adapter/web/PlayerFacadeTypes.ts +14 -0
  237. package/src/internal/drm/ContentProtectionRegistry.ts +35 -17
  238. package/src/internal/drm/NativeContentProtectionEvent.ts +5 -0
  239. package/src/manifest.json +1 -1
  240. package/src/plugins/typedoc-platform-icons/package-lock.json +200 -58
  241. package/src/plugins/typedoc-platform-icons/package.json +1 -1
  242. package/src/plugins/typedoc-platform-icons/tsconfig.json +2 -1
  243. package/lib/typescript/plugins/expo/Common.d.ts +0 -13
  244. package/lib/typescript/plugins/expo/Common.d.ts.map +0 -1
  245. package/lib/typescript/plugins/expo/withCustomPod.d.ts +0 -2
  246. package/lib/typescript/plugins/expo/withCustomPod.d.ts.map +0 -1
  247. package/lib/typescript/plugins/expo/withTHEOplayer.d.ts +0 -4
  248. package/lib/typescript/plugins/expo/withTHEOplayer.d.ts.map +0 -1
  249. package/lib/typescript/plugins/expo/withTHEOplayerAndroid.d.ts +0 -4
  250. package/lib/typescript/plugins/expo/withTHEOplayerAndroid.d.ts.map +0 -1
  251. package/lib/typescript/plugins/expo/withTHEOplayerIOS.d.ts +0 -4
  252. package/lib/typescript/plugins/expo/withTHEOplayerIOS.d.ts.map +0 -1
  253. package/lib/typescript/plugins/typedoc-platform-icons/src/index.d.ts +0 -3
  254. package/lib/typescript/plugins/typedoc-platform-icons/src/index.d.ts.map +0 -1
@@ -37,6 +37,7 @@ import com.theoplayer.android.connector.mediasession.MediaSessionConnector
37
37
  import com.theoplayer.audio.AudioBecomingNoisyManager
38
38
  import com.theoplayer.audio.AudioFocusManager
39
39
  import com.theoplayer.audio.BackgroundAudioConfig
40
+ import com.theoplayer.integration.PlayerFacade
40
41
  import com.theoplayer.media.MediaControlProxy
41
42
  import com.theoplayer.media.MediaPlaybackService
42
43
  import com.theoplayer.media.MediaSessionConfig
@@ -51,6 +52,7 @@ class ReactTHEOplayerContext private constructor(
51
52
  private val mainHandler = Handler(Looper.getMainLooper())
52
53
  private var isBound = AtomicBoolean()
53
54
  private var binder: MediaPlaybackService.MediaPlaybackBinder? = null
55
+ private var isDestroyed = false
54
56
 
55
57
  private var audioBecomingNoisyManager = AudioBecomingNoisyManager(reactContext) {
56
58
  // Audio is about to become 'noisy' due to a change in audio outputs: pause the player
@@ -101,9 +103,11 @@ class ReactTHEOplayerContext private constructor(
101
103
  }
102
104
 
103
105
  lateinit var playerView: THEOplayerView
106
+ lateinit var player: Player
107
+ private set
104
108
 
105
- val player: Player
106
- get() = playerView.player
109
+ val playerFacade: PlayerFacade?
110
+ get() = player as? PlayerFacade
107
111
 
108
112
  private val uiModeManager by lazy {
109
113
  reactContext.getSystemService(Context.UI_MODE_SERVICE) as? UiModeManager
@@ -135,6 +139,17 @@ class ReactTHEOplayerContext private constructor(
135
139
 
136
140
  private val connection = object : ServiceConnection {
137
141
  override fun onServiceConnected(className: ComponentName, service: IBinder) {
142
+ // The context may have been destroyed while the bind was still pending.
143
+ // Do not attach the destroyed player/context to the service.
144
+ if (isDestroyed) {
145
+ try {
146
+ reactContext.unbindService(this)
147
+ } catch (e: IllegalArgumentException) {
148
+ // Connection was not registered or already unbound; ignore.
149
+ }
150
+ return
151
+ }
152
+
138
153
  binder = service as MediaPlaybackService.MediaPlaybackBinder
139
154
 
140
155
  // Get media session connector from service
@@ -202,11 +217,13 @@ class ReactTHEOplayerContext private constructor(
202
217
  }
203
218
 
204
219
  private fun unbindMediaPlaybackService() {
205
- // This client is done interacting with the service: unbind.
206
- // When there are no clients bound to the service, the system destroys the service.
207
- if (binder?.isBinderAlive == true) {
208
- if (isBound.getAndSet(false)) {
220
+ // Always unbind when isBound, regardless of whether the binder is alive yet: a pending
221
+ // bind must still be cancelled so a late callback cannot resurrect this.
222
+ if (isBound.getAndSet(false)) {
223
+ try {
209
224
  reactContext.unbindService(connection)
225
+ } catch (e: IllegalArgumentException) {
226
+ // Service was not registered or already unbound; ignore.
210
227
  }
211
228
  }
212
229
  binder = null
@@ -234,6 +251,7 @@ class ReactTHEOplayerContext private constructor(
234
251
  mainHandler.post { measureAndLayout() }
235
252
  }
236
253
  }
254
+ player = PlayerFacade.create(playerView.player, configAdapter.usePlayerFacade())
237
255
 
238
256
  // By default, choose SURFACE_CONTROL/SURFACE_VIEW rendering target, based on API level.
239
257
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
@@ -472,8 +490,13 @@ class ReactTHEOplayerContext private constructor(
472
490
  }
473
491
 
474
492
  fun destroy() {
493
+ isDestroyed = true
475
494
  removeListeners()
476
495
 
496
+ // The media session can be shared with other player contexts through the playback service.
497
+ // Determine ownership before unbinding, as that clears the binder needed to check it.
498
+ val ownedMediaSession = ownsMediaSession()
499
+
477
500
  if (BuildConfig.USE_PLAYBACK_SERVICE) {
478
501
  // Remove service from foreground
479
502
  binder?.stopForegroundService()
@@ -483,7 +506,13 @@ class ReactTHEOplayerContext private constructor(
483
506
  }
484
507
  audioFocusManager?.abandonAudioFocus()
485
508
  mediaControlProxy.destroy()
486
- mediaSessionConnector?.destroy()
487
- playerView.onDestroy()
509
+ if (ownedMediaSession) {
510
+ // Only tear down the session when another player did not take it over: a queued callback
511
+ // must never reach this destroyed player, but a newly-activated player must keep working.
512
+ mediaSessionConnector?.player = null
513
+ mediaSessionConnector?.destroy()
514
+ }
515
+ val facade = playerFacade
516
+ if (facade != null) facade.destroyContent { playerView.onDestroy() } else playerView.onDestroy()
488
517
  }
489
518
  }
@@ -11,6 +11,7 @@ import com.theoplayer.drm.ContentProtectionModule
11
11
  import com.theoplayer.cast.CastModule
12
12
  import com.theoplayer.broadcast.EventBroadcastModule
13
13
  import com.theoplayer.media.MediaControlModule
14
+ import com.theoplayer.metrics.MetricsModule
14
15
  import com.theoplayer.player.PlayerModule
15
16
  import com.theoplayer.theolive.THEOliveModule
16
17
  import com.theoplayer.theoads.THEOadsModule
@@ -28,6 +29,7 @@ class ReactTHEOplayerPackage : BaseReactPackage() {
28
29
  THEOliveModule.NAME -> THEOliveModule(reactContext)
29
30
  THEOadsModule.NAME -> THEOadsModule(reactContext)
30
31
  MediaControlModule.NAME -> MediaControlModule(reactContext)
32
+ MetricsModule.NAME -> MetricsModule(reactContext)
31
33
  else -> null
32
34
  }
33
35
  }
@@ -48,6 +50,7 @@ class ReactTHEOplayerPackage : BaseReactPackage() {
48
50
  THEOliveModule.NAME to THEOliveModule.INFO,
49
51
  THEOadsModule.NAME to THEOadsModule.INFO,
50
52
  MediaControlModule.NAME to MediaControlModule.INFO,
53
+ MetricsModule.NAME to MetricsModule.INFO,
51
54
  )
52
55
  }
53
56
  }
@@ -2,8 +2,10 @@ package com.theoplayer
2
2
 
3
3
  import android.annotation.SuppressLint
4
4
  import android.util.Log
5
+ import android.view.View
5
6
  import android.view.ViewGroup
6
7
  import android.widget.FrameLayout
8
+ import androidx.annotation.MainThread
7
9
  import com.facebook.react.bridge.*
8
10
  import com.facebook.react.uimanager.ThemedReactContext
9
11
  import com.theoplayer.android.api.ads.wrapper.AdsApiWrapper
@@ -11,6 +13,9 @@ import com.theoplayer.android.api.cast.Cast
11
13
  import com.theoplayer.android.api.error.THEOplayerException
12
14
  import com.theoplayer.android.api.player.Player
13
15
  import com.theoplayer.broadcast.EventBroadcastAdapter
16
+ import com.theoplayer.integration.Integration
17
+ import com.theoplayer.integration.IntegrationRegistration
18
+ import com.theoplayer.integration.PlayerFacadeAdsBridge
14
19
  import com.theoplayer.presentation.PresentationManager
15
20
  import com.theoplayer.source.SourceAdapter
16
21
 
@@ -31,7 +36,9 @@ class ReactTHEOplayerView(private val reactContext: ThemedReactContext) :
31
36
  private set
32
37
  private var config: PlayerConfigAdapter? = null
33
38
 
39
+ /** Native source-specific Ads adapter and event sink. Use [player]'s Ads API for integration-owned state. */
34
40
  val adsApi: AdsApiWrapper
41
+ internal val adBridge: PlayerFacadeAdsBridge
35
42
 
36
43
  val castApi: Cast?
37
44
  get() = playerContext?.playerView?.cast
@@ -39,9 +46,31 @@ class ReactTHEOplayerView(private val reactContext: ThemedReactContext) :
39
46
  val player: Player?
40
47
  get() = playerContext?.player
41
48
 
49
+ /**
50
+ * Registers playback and advertising overrides on the player facade.
51
+ *
52
+ * Experimental API: subject to change or removal without notice.
53
+ *
54
+ * Enable `config.usePlayerFacade` before creating the player and wait until this view is initialized.
55
+ * Only one integration can be registered at a time; close its registration before replacing it.
56
+ *
57
+ * @param integration The hooks and optional Ads API to use until registration closes.
58
+ * @return The registration used to dispatch events, intercept native events, and unregister.
59
+ * @throws IllegalStateException if the view is uninitialized, the facade is disabled or closed,
60
+ * or another integration is already registered.
61
+ */
62
+ @MainThread
63
+ fun registerIntegration(integration: Integration): IntegrationRegistration {
64
+ val context = checkNotNull(playerContext) { "The player view has not been initialized." }
65
+ return checkNotNull(context.playerFacade) {
66
+ "Set config.usePlayerFacade to true at player creation before registering an integration."
67
+ }.registerIntegration(integration)
68
+ }
69
+
42
70
  init {
43
71
  reactContext.addLifecycleEventListener(this)
44
72
  adsApi = AdsApiWrapper()
73
+ adBridge = PlayerFacadeAdsBridge(adsApi)
45
74
  }
46
75
 
47
76
  fun initialize(config: PlayerConfigAdapter) {
@@ -63,11 +92,12 @@ class ReactTHEOplayerView(private val reactContext: ThemedReactContext) :
63
92
  config
64
93
  )
65
94
  playerContext?.apply {
66
- adsApi.initialize(player, imaIntegration, daiIntegration)
95
+ adBridge.initialize(player, imaIntegration, daiIntegration)
67
96
  val layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
68
97
  playerView.layoutParams = layoutParams
69
98
  (playerView.parent as? ViewGroup)?.removeView(playerView)
70
99
  addView(playerView, 0, layoutParams)
100
+ measureAndLayoutPlayerView()
71
101
  presentationManager = PresentationManager(
72
102
  this,
73
103
  reactContext,
@@ -82,6 +112,24 @@ class ReactTHEOplayerView(private val reactContext: ThemedReactContext) :
82
112
  if (!isInitialized && BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
83
113
  config?.let { initialize(it) }
84
114
  }
115
+ measureAndLayoutPlayerView()
116
+ }
117
+
118
+ override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
119
+ super.onSizeChanged(w, h, oldw, oldh)
120
+ measureAndLayoutPlayerView()
121
+ }
122
+
123
+ private fun measureAndLayoutPlayerView() {
124
+ val playerView = playerContext?.playerView ?: return
125
+ if (width == 0 || height == 0) return
126
+ if (playerView.width == width && playerView.height == height) return
127
+
128
+ playerView.measure(
129
+ View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
130
+ View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY)
131
+ )
132
+ playerView.layout(0, 0, width, height)
85
133
  }
86
134
 
87
135
  override fun setId(id: Int) {
@@ -128,7 +176,7 @@ class ReactTHEOplayerView(private val reactContext: ThemedReactContext) :
128
176
  Log.d(TAG, "releasePlayer")
129
177
  }
130
178
  reactContext.removeLifecycleEventListener(this)
131
- adsApi.destroy()
179
+ adBridge.destroy()
132
180
 
133
181
  if (isInitialized) {
134
182
  eventEmitter.removeListeners(player)
@@ -141,7 +189,7 @@ class ReactTHEOplayerView(private val reactContext: ThemedReactContext) :
141
189
  fun setSource(source: ReadableMap?) {
142
190
  try {
143
191
  val sourceDescription = SourceAdapter().parseSourceFromJS(source)
144
- adsApi.setSource(sourceDescription)
192
+ adBridge.setSource(sourceDescription)
145
193
  player?.source = sourceDescription
146
194
  } catch (exception: THEOplayerException) {
147
195
  Log.e(TAG, exception.message ?: "")
@@ -51,6 +51,8 @@ class AdEventAdapter(private val adsApi: AdsApiWrapper, eventEmitter: AdEventEmi
51
51
 
52
52
  init {
53
53
  adsApi.addAllEventsListener(eventListener)
54
+ adsApi.addEventListener(AdsEventTypes.AD_CLICKED, eventListener)
55
+ adsApi.addEventListener(AdsEventTypes.AD_TAPPED, eventListener)
54
56
  }
55
57
 
56
58
  companion object {
@@ -131,5 +133,7 @@ class AdEventAdapter(private val adsApi: AdsApiWrapper, eventEmitter: AdEventEmi
131
133
 
132
134
  fun destroy() {
133
135
  adsApi.removeAllEventsListener(eventListener)
136
+ adsApi.removeEventListener(AdsEventTypes.AD_CLICKED, eventListener)
137
+ adsApi.removeEventListener(AdsEventTypes.AD_TAPPED, eventListener)
134
138
  }
135
139
  }
@@ -45,7 +45,7 @@ class AdsModule(context: ReactApplicationContext) : ReactContextBaseJavaModule(c
45
45
  fun schedule(tag: Int, ad: ReadableMap) {
46
46
  viewResolver.resolveViewByTag(tag) { view: ReactTHEOplayerView? ->
47
47
  try {
48
- view?.adsApi?.schedule(sourceHelper.parseAdDescriptionFromJS(ad))
48
+ view?.adBridge?.schedule(sourceHelper.parseAdDescriptionFromJS(ad))
49
49
  } catch (exception: THEOplayerException) {
50
50
  Log.e(NAME, exception.message ?: ERR_SCHEDULE_AD)
51
51
  }
@@ -56,7 +56,7 @@ class AdsModule(context: ReactApplicationContext) : ReactContextBaseJavaModule(c
56
56
  @ReactMethod
57
57
  fun currentAdBreak(tag: Int, promise: Promise) {
58
58
  viewResolver.resolveViewByTag(tag) { view: ReactTHEOplayerView? ->
59
- promise.resolve(if (view == null) Arguments.createMap() else AdAdapter.fromAdBreak(view.adsApi.currentAdBreak))
59
+ promise.resolve(if (view == null) Arguments.createMap() else AdAdapter.fromAdBreak(view.adBridge.currentAdBreak))
60
60
  }
61
61
  }
62
62
 
@@ -64,7 +64,7 @@ class AdsModule(context: ReactApplicationContext) : ReactContextBaseJavaModule(c
64
64
  @ReactMethod
65
65
  fun currentAds(tag: Int, promise: Promise) {
66
66
  viewResolver.resolveViewByTag(tag) { view: ReactTHEOplayerView? ->
67
- promise.resolve(if (view == null) Arguments.createArray() else AdAdapter.fromAds(view.adsApi.currentAds))
67
+ promise.resolve(if (view == null) Arguments.createArray() else AdAdapter.fromAds(view.adBridge.currentAds))
68
68
  }
69
69
  }
70
70
 
@@ -72,7 +72,7 @@ class AdsModule(context: ReactApplicationContext) : ReactContextBaseJavaModule(c
72
72
  @ReactMethod
73
73
  fun scheduledAdBreaks(tag: Int, promise: Promise) {
74
74
  viewResolver.resolveViewByTag(tag) { view: ReactTHEOplayerView? ->
75
- promise.resolve(if (view == null) Arguments.createArray() else AdAdapter.fromAdBreaks(view.adsApi.scheduledAdBreaks))
75
+ promise.resolve(if (view == null) Arguments.createArray() else AdAdapter.fromAdBreaks(view.adBridge.scheduledAdBreaks))
76
76
  }
77
77
  }
78
78
 
@@ -80,7 +80,7 @@ class AdsModule(context: ReactApplicationContext) : ReactContextBaseJavaModule(c
80
80
  @ReactMethod
81
81
  fun playing(tag: Int, promise: Promise) {
82
82
  viewResolver.resolveViewByTag(tag) { view: ReactTHEOplayerView? ->
83
- promise.resolve(view?.adsApi?.isPlaying ?: false)
83
+ promise.resolve(view?.adBridge?.isPlaying ?: false)
84
84
  }
85
85
  }
86
86
 
@@ -88,7 +88,7 @@ class AdsModule(context: ReactApplicationContext) : ReactContextBaseJavaModule(c
88
88
  // NOTE: This will have no effect when the current linear ad is not (yet) skippable.
89
89
  @ReactMethod
90
90
  fun skip(tag: Int) {
91
- viewResolver.resolveViewByTag(tag) { view: ReactTHEOplayerView? -> view?.adsApi?.skip() }
91
+ viewResolver.resolveViewByTag(tag) { view: ReactTHEOplayerView? -> view?.adBridge?.skip() }
92
92
  }
93
93
 
94
94
  @ReactMethod
@@ -22,6 +22,7 @@ private const val TAG = "ContentProtection"
22
22
 
23
23
  const val PROP_INTEGRATION: String = "integration"
24
24
  const val PROP_INTEGRATION_ID: String = "integrationId"
25
+ const val PROP_INTEGRATION_INSTANCE_ID: String = "integrationInstanceId"
25
26
  const val PROP_INTEGRATION_PARAMETERS: String = "integrationParameters"
26
27
  const val PROP_REQUEST: String = "request"
27
28
  const val PROP_KEYSYSTEM_ID: String = "keySystemId"
@@ -51,9 +52,14 @@ const val PROP_VALUE: String = "value"
51
52
 
52
53
  object ContentProtectionAdapter {
53
54
 
54
- private fun createBridgeData(integrationId: String, keySystemId: KeySystemId): WritableMap {
55
+ private fun createBridgeData(
56
+ integrationId: String,
57
+ keySystemId: KeySystemId,
58
+ integrationInstanceId: String
59
+ ): WritableMap {
55
60
  return Arguments.createMap().apply {
56
61
  putString(PROP_INTEGRATION_ID, integrationId)
62
+ putString(PROP_INTEGRATION_INSTANCE_ID, integrationInstanceId)
57
63
  putString(PROP_KEYSYSTEM_ID, KeySystemAdapter.toString(keySystemId))
58
64
  }
59
65
  }
@@ -176,8 +182,13 @@ object ContentProtectionAdapter {
176
182
  }
177
183
  }
178
184
 
179
- fun fromRequest(integrationId: String, keySystemId: KeySystemId, request: Request): WritableMap {
180
- val payload = createBridgeData(integrationId, keySystemId)
185
+ fun fromRequest(
186
+ integrationId: String,
187
+ keySystemId: KeySystemId,
188
+ integrationInstanceId: String,
189
+ request: Request
190
+ ): WritableMap {
191
+ val payload = createBridgeData(integrationId, keySystemId, integrationInstanceId)
181
192
  payload.putString(PROP_URL, request.url)
182
193
  payload.putString(PROP_METHOD, RequestMethodAdapter.toString(request.method))
183
194
  val headers = Arguments.createMap()
@@ -192,9 +203,10 @@ object ContentProtectionAdapter {
192
203
  fun fromResponse(
193
204
  integrationId: String,
194
205
  keySystemId: KeySystemId,
206
+ integrationInstanceId: String,
195
207
  response: Response
196
208
  ): WritableMap {
197
- val payload = createBridgeData(integrationId, keySystemId)
209
+ val payload = createBridgeData(integrationId, keySystemId, integrationInstanceId)
198
210
  payload.putString(PROP_URL, response.url)
199
211
  payload.putInt(PROP_STATUS, response.status)
200
212
  payload.putString(PROP_STATUS_TEXT, response.statusText)
@@ -205,7 +217,7 @@ object ContentProtectionAdapter {
205
217
  }
206
218
  }
207
219
  payload.putMap(PROP_HEADERS, headers)
208
- payload.putMap(PROP_REQUEST, fromRequest(integrationId, keySystemId, response.request))
220
+ payload.putMap(PROP_REQUEST, fromRequest(integrationId, keySystemId, integrationInstanceId, response.request))
209
221
  payload.putString(PROP_BASE64_BODY, Base64.encodeToString(response.body, Base64.DEFAULT))
210
222
  return payload
211
223
  }
@@ -14,6 +14,7 @@ import com.theoplayer.android.api.contentprotection.*
14
14
  import com.theoplayer.android.api.error.ErrorCode
15
15
  import com.theoplayer.android.api.error.THEOplayerException
16
16
  import com.theoplayer.android.api.source.drm.DRMConfiguration
17
+ import java.lang.ref.WeakReference
17
18
 
18
19
  data class BridgeRequest(
19
20
  val onResult: HashMap<String, (result: ReadableMap) -> Unit>,
@@ -35,6 +36,7 @@ private const val EVENT_LICENSE_REQUEST_PROCESSED_AS_REQUEST = "onLicenseRequest
35
36
  private const val EVENT_LICENSE_REQUEST_PROCESSED_AS_LICENSE = "onLicenseRequestProcessedAsLicense"
36
37
  private const val EVENT_LICENSE_RESPONSE = "onLicenseResponse"
37
38
  private const val EVENT_LICENSE_RESPONSE_PROCESSED = "onLicenseResponseProcessed"
39
+ private const val EVENT_INTEGRATION_DISPOSED = "onIntegrationDisposed"
38
40
 
39
41
  @Suppress("unused")
40
42
  @ReactModule(name = ContentProtectionModule.NAME)
@@ -52,6 +54,7 @@ class ContentProtectionModule(private val context: ReactApplicationContext) :
52
54
  isTurboModule = false,
53
55
  )
54
56
  const val REQUEST_TIMEOUT_MS = 10000L
57
+ const val PRUNE_INTERVAL_MS = 30000L
55
58
  }
56
59
 
57
60
  private val handler = Handler(Looper.getMainLooper())
@@ -60,6 +63,47 @@ class ContentProtectionModule(private val context: ReactApplicationContext) :
60
63
 
61
64
  private val requestQueue: HashMap<String, BridgeRequest> = HashMap()
62
65
 
66
+ // Weak references to every proxy integration instance built by the native SDK.
67
+ // The Android content protection API has no disposal callback, so instance
68
+ // cleanup is detected through garbage collection and reported to JavaScript.
69
+ private val integrationRefs: HashMap<String, WeakReference<ProxyContentProtectionIntegration>> = HashMap()
70
+
71
+ // Periodically reports collected proxy instances to JavaScript, so cleanup also
72
+ // happens when no further DRM events trigger it.
73
+ private val pruneRunnable = object : Runnable {
74
+ override fun run() {
75
+ pruneDisposedIntegrations()
76
+ if (integrationRefs.isNotEmpty()) {
77
+ handler.postDelayed(this, PRUNE_INTERVAL_MS)
78
+ }
79
+ }
80
+ }
81
+
82
+ fun trackIntegration(integration: ProxyContentProtectionIntegration) {
83
+ integrationRefs[integration.integrationInstanceId] = WeakReference(integration)
84
+ if (integrationRefs.size == 1) {
85
+ handler.postDelayed(pruneRunnable, PRUNE_INTERVAL_MS)
86
+ }
87
+ }
88
+
89
+ override fun invalidate() {
90
+ handler.removeCallbacks(pruneRunnable)
91
+ super.invalidate()
92
+ }
93
+
94
+ private fun pruneDisposedIntegrations() {
95
+ val disposed = integrationRefs.filterValues { it.get() == null }.keys
96
+ disposed.forEach { integrationInstanceId ->
97
+ integrationRefs.remove(integrationInstanceId)
98
+ context.getJSModule(RCTDeviceEventEmitter::class.java).emit(
99
+ EVENT_INTEGRATION_DISPOSED,
100
+ Arguments.createMap().apply {
101
+ putString(PROP_INTEGRATION_INSTANCE_ID, integrationInstanceId)
102
+ }
103
+ )
104
+ }
105
+ }
106
+
63
107
  override fun getName(): String {
64
108
  return NAME
65
109
  }
@@ -117,8 +161,8 @@ class ContentProtectionModule(private val context: ReactApplicationContext) :
117
161
  receive(EVENT_LICENSE_RESPONSE_PROCESSED, payload)
118
162
  }
119
163
 
120
- fun onBuild(integrationId: String, keySystemId: KeySystemId, config: DRMConfiguration?) {
121
- val payload = createBridgeData(integrationId, keySystemId)
164
+ fun onBuild(integrationId: String, keySystemId: KeySystemId, integrationInstanceId: String, config: DRMConfiguration?) {
165
+ val payload = createBridgeData(integrationId, keySystemId, integrationInstanceId)
122
166
  if (config != null) {
123
167
  payload.putMap(PROP_DRM_CONFIG, ContentProtectionAdapter.fromDRMConfiguration(config))
124
168
  }
@@ -132,10 +176,11 @@ class ContentProtectionModule(private val context: ReactApplicationContext) :
132
176
  fun onCertificateRequest(
133
177
  integrationId: String,
134
178
  keySystemId: KeySystemId,
179
+ integrationInstanceId: String,
135
180
  request: Request,
136
181
  callback: CertificateRequestCallback
137
182
  ) {
138
- val payload = ContentProtectionAdapter.fromRequest(integrationId, keySystemId, request)
183
+ val payload = ContentProtectionAdapter.fromRequest(integrationId, keySystemId, integrationInstanceId, request)
139
184
  emit(
140
185
  EVENT_CERTIFICATE_REQUEST, payload,
141
186
  onResult = hashMapOf(
@@ -163,10 +208,11 @@ class ContentProtectionModule(private val context: ReactApplicationContext) :
163
208
  fun onCertificateResponse(
164
209
  integrationId: String,
165
210
  keySystemId: KeySystemId,
211
+ integrationInstanceId: String,
166
212
  response: Response,
167
213
  callback: CertificateResponseCallback
168
214
  ) {
169
- val payload = ContentProtectionAdapter.fromResponse(integrationId, keySystemId, response)
215
+ val payload = ContentProtectionAdapter.fromResponse(integrationId, keySystemId, integrationInstanceId, response)
170
216
  emit(
171
217
  EVENT_CERTIFICATE_RESPONSE, payload,
172
218
  onResult = hashMapOf(
@@ -182,10 +228,11 @@ class ContentProtectionModule(private val context: ReactApplicationContext) :
182
228
  fun onLicenseRequest(
183
229
  integrationId: String,
184
230
  keySystemId: KeySystemId,
231
+ integrationInstanceId: String,
185
232
  request: Request,
186
233
  callback: LicenseRequestCallback
187
234
  ) {
188
- val payload = ContentProtectionAdapter.fromRequest(integrationId, keySystemId, request)
235
+ val payload = ContentProtectionAdapter.fromRequest(integrationId, keySystemId, integrationInstanceId, request)
189
236
  emit(
190
237
  EVENT_LICENSE_REQUEST, payload,
191
238
  onResult = hashMapOf(
@@ -213,10 +260,11 @@ class ContentProtectionModule(private val context: ReactApplicationContext) :
213
260
  fun onLicenseResponse(
214
261
  integrationId: String,
215
262
  keySystemId: KeySystemId,
263
+ integrationInstanceId: String,
216
264
  response: Response,
217
265
  callback: LicenseResponseCallback
218
266
  ) {
219
- val payload = ContentProtectionAdapter.fromResponse(integrationId, keySystemId, response)
267
+ val payload = ContentProtectionAdapter.fromResponse(integrationId, keySystemId, integrationInstanceId, response)
220
268
  emit(
221
269
  EVENT_LICENSE_RESPONSE, payload,
222
270
  onResult = hashMapOf(
@@ -246,6 +294,7 @@ class ContentProtectionModule(private val context: ReactApplicationContext) :
246
294
  onResult: HashMap<String, (result: ReadableMap) -> Unit>,
247
295
  onError: (error: THEOplayerException) -> Unit
248
296
  ) {
297
+ pruneDisposedIntegrations()
249
298
  val requestId = createRequestId()
250
299
  if (BuildConfig.DEBUG) {
251
300
  Log.d(NAME, "emit $eventName ($requestId)")
@@ -289,9 +338,14 @@ class ContentProtectionModule(private val context: ReactApplicationContext) :
289
338
  return (requestId++).toString()
290
339
  }
291
340
 
292
- private fun createBridgeData(integrationId: String, keySystemId: KeySystemId): WritableMap {
341
+ private fun createBridgeData(
342
+ integrationId: String,
343
+ keySystemId: KeySystemId,
344
+ integrationInstanceId: String
345
+ ): WritableMap {
293
346
  return Arguments.createMap().apply {
294
347
  putString(PROP_INTEGRATION_ID, integrationId)
348
+ putString(PROP_INTEGRATION_INSTANCE_ID, integrationInstanceId)
295
349
  putString(PROP_KEYSYSTEM_ID, KeySystemAdapter.toString(keySystemId))
296
350
  }
297
351
  }
@@ -2,6 +2,7 @@ package com.theoplayer.drm
2
2
 
3
3
  import com.theoplayer.android.api.contentprotection.*
4
4
  import com.theoplayer.android.api.source.drm.DRMConfiguration
5
+ import java.util.UUID
5
6
 
6
7
  class ProxyContentProtectionIntegration(
7
8
  private val integrationId: String,
@@ -10,23 +11,29 @@ class ProxyContentProtectionIntegration(
10
11
  private val module: ContentProtectionModule
11
12
  ) : ContentProtectionIntegration() {
12
13
 
14
+ /**
15
+ * Unique identifier for this integration instance, shared with the JavaScript
16
+ * content protection registry to route callbacks to the matching integration.
17
+ */
18
+ val integrationInstanceId: String = UUID.randomUUID().toString()
19
+
13
20
  init {
14
- module.onBuild(integrationId, keySystemId, config)
21
+ module.onBuild(integrationId, keySystemId, integrationInstanceId, config)
15
22
  }
16
23
 
17
24
  override fun onCertificateRequest(request: Request, callback: CertificateRequestCallback) {
18
- module.onCertificateRequest(integrationId, keySystemId, request, callback)
25
+ module.onCertificateRequest(integrationId, keySystemId, integrationInstanceId, request, callback)
19
26
  }
20
27
 
21
28
  override fun onCertificateResponse(response: Response, callback: CertificateResponseCallback) {
22
- module.onCertificateResponse(integrationId, keySystemId, response, callback)
29
+ module.onCertificateResponse(integrationId, keySystemId, integrationInstanceId, response, callback)
23
30
  }
24
31
 
25
32
  override fun onLicenseRequest(request: Request, callback: LicenseRequestCallback) {
26
- module.onLicenseRequest(integrationId, keySystemId, request, callback)
33
+ module.onLicenseRequest(integrationId, keySystemId, integrationInstanceId, request, callback)
27
34
  }
28
35
 
29
36
  override fun onLicenseResponse(response: Response, callback: LicenseResponseCallback) {
30
- module.onLicenseResponse(integrationId, keySystemId, response, callback)
37
+ module.onLicenseResponse(integrationId, keySystemId, integrationInstanceId, response, callback)
31
38
  }
32
39
  }
@@ -12,6 +12,8 @@ class ProxyContentProtectionIntegrationFactory(
12
12
  ) : ContentProtectionIntegrationFactory {
13
13
 
14
14
  override fun build(config: DRMConfiguration): ContentProtectionIntegration {
15
- return ProxyContentProtectionIntegration(integrationId, keySystemId, config, module)
15
+ return ProxyContentProtectionIntegration(integrationId, keySystemId, config, module).also {
16
+ module.trackIntegration(it)
17
+ }
16
18
  }
17
19
  }
@@ -0,0 +1,72 @@
1
+ package com.theoplayer.integration
2
+
3
+ import androidx.annotation.MainThread
4
+ import com.theoplayer.android.api.ads.Ads
5
+ import com.theoplayer.android.api.event.ads.AdEvent
6
+
7
+ /**
8
+ * Optional playback and advertising overrides for [PlayerFacade].
9
+ *
10
+ * Experimental API: subject to change or removal without notice.
11
+ *
12
+ * Enable `usePlayerFacade` at player creation and register through [com.theoplayer.ReactTHEOplayerView.registerIntegration].
13
+ * Unimplemented hooks delegate to the content player. The integration owns playback synchronization,
14
+ * advertising lifecycle, and events describing its public state. All hooks run on the main thread.
15
+ *
16
+ * Custom advertising must not overlap ongoing native IMA/DAI playback. Replacing or filtering native
17
+ * advertising events can suspend the React Native bridge's native DAI bookkeeping; fresh native state
18
+ * after hidden native playback is not guaranteed. Finish or reset native advertising before taking over.
19
+ */
20
+ @MainThread
21
+ interface Integration {
22
+ /** Returns a finite, non-negative time in seconds, or null to delegate. Invalid times also delegate. */
23
+ fun getCurrentTime(): Double? = null
24
+
25
+ /** Seeks to [currentTime] in seconds. Returns true if handled, or false to seek the content player. */
26
+ fun setCurrentTime(currentTime: Double): Boolean = false
27
+
28
+ /** Starts or resumes playback. Returns true if handled, or false to play the content player. */
29
+ fun play(): Boolean = false
30
+
31
+ /** Pauses playback. Returns true if handled, or false to pause the content player. */
32
+ fun pause(): Boolean = false
33
+
34
+ /** Returns the paused state, or null to use the content player's state. */
35
+ fun isPaused(): Boolean? = null
36
+
37
+ /** Returns the seeking state, or null to use the content player's state. */
38
+ fun isSeeking(): Boolean? = null
39
+
40
+ /** Returns the duration in seconds, or null to delegate. Infinity and NaN are preserved. */
41
+ fun getDuration(): Double? = null
42
+
43
+ /** Returns the muted state, or null to use the content player's state. */
44
+ fun getMuted(): Boolean? = null
45
+
46
+ /** Sets [muted]. Returns true if handled, or false to update the content player. */
47
+ fun setMuted(muted: Boolean): Boolean = false
48
+
49
+ /** Returns the volume between 0 and 1, or null to use the content player's volume. */
50
+ fun getVolume(): Double? = null
51
+
52
+ /** Sets [volume] between 0 and 1. Returns true if handled, or false to update the content player. */
53
+ fun setVolume(volume: Double): Boolean = false
54
+
55
+ /**
56
+ * The Ads API and event source behind the stable facade Ads object, or null to retain native Ads.
57
+ * Keep this object stable until registration closes. Existing listeners migrate on registration and close.
58
+ */
59
+ val ads: Ads? get() = null
60
+
61
+ /**
62
+ * Returns advertising state without replacing the native Ads API, or null to delegate.
63
+ * Ignored when [ads] is supplied. State is never derived from dispatched events.
64
+ */
65
+ fun getAdState(): PlayerFacadeAdState? = null
66
+
67
+ /**
68
+ * Returns true to consume a native Ads [event] for all facade listeners, or false to forward it.
69
+ * Called once per subscribed event. Integration-generated events bypass this hook.
70
+ */
71
+ fun shouldConsumeAdEvent(event: AdEvent<*>): Boolean = false
72
+ }