react-native-theoplayer 11.4.1 → 11.6.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 (155) hide show
  1. package/CHANGELOG.md +26 -1
  2. package/README.md +1 -0
  3. package/android/src/main/java/com/theoplayer/PlayerEventEmitter.kt +21 -0
  4. package/android/src/main/java/com/theoplayer/ReactTHEOplayerContext.kt +58 -85
  5. package/android/src/main/java/com/theoplayer/ReactTHEOplayerPackage.kt +3 -0
  6. package/android/src/main/java/com/theoplayer/media/MediaControlModule.kt +102 -0
  7. package/android/src/main/java/com/theoplayer/media/MediaControlProxy.kt +376 -0
  8. package/android/src/main/java/com/theoplayer/media/MediaNotificationBuilder.kt +78 -34
  9. package/android/src/main/java/com/theoplayer/media/MediaPlaybackService.kt +53 -20
  10. package/android/src/main/java/com/theoplayer/media/MediaSessionConfig.kt +6 -6
  11. package/android/src/main/java/com/theoplayer/media/MediaSessionConfigAdapter.kt +23 -20
  12. package/android/src/main/java/com/theoplayer/player/PlayerModule.kt +0 -1
  13. package/android/src/main/java/com/theoplayer/presentation/PipUtils.kt +98 -93
  14. package/android/src/main/java/com/theoplayer/util/ReadableExtension.kt +14 -0
  15. package/android/src/main/res/drawable/ic_next.xml +9 -0
  16. package/android/src/main/res/drawable/ic_prev.xml +9 -0
  17. package/android/src/main/res/values/strings.xml +4 -0
  18. package/ios/RCTBridgeModule+ViewHelpers.swift +59 -0
  19. package/ios/THEOplayerRCTBridge.m +17 -0
  20. package/ios/THEOplayerRCTDebug.swift +3 -0
  21. package/ios/THEOplayerRCTMainEventHandler.swift +18 -0
  22. package/ios/THEOplayerRCTPlayerAPI.swift +194 -254
  23. package/ios/THEOplayerRCTTypeUtils.swift +30 -0
  24. package/ios/THEOplayerRCTView.swift +22 -6
  25. package/ios/ads/THEOplayerRCTAdsAPI+DAI.swift +22 -21
  26. package/ios/ads/THEOplayerRCTAdsAPI+Omid.swift +4 -9
  27. package/ios/ads/THEOplayerRCTAdsAPI.swift +39 -50
  28. package/ios/backgroundAudio/THEOplayerRCTBackgroundAudioManager.swift +2 -2
  29. package/ios/backgroundAudio/THEOplayerRCTNowPlayingManager.swift +144 -47
  30. package/ios/backgroundAudio/THEOplayerRCTRemoteCommandsManager.swift +151 -68
  31. package/ios/backgroundAudio/THEOplayerRCTView+MediaControlConfig.swift +25 -11
  32. package/ios/casting/THEOplayerRCTCastAPI+Airplay.swift +20 -22
  33. package/ios/casting/THEOplayerRCTCastAPI+Chromecast.swift +28 -34
  34. package/ios/casting/THEOplayerRCTCastAPI.swift +5 -8
  35. package/ios/eventBroadcasting/THEOplayerRCTEventBroadcastAPI.swift +2 -4
  36. package/ios/mediaControl/THEOplayerRCTMediaControlAPI.swift +79 -0
  37. package/ios/mediaControl/THEOplayerRCTMediaControlManager.swift +38 -0
  38. package/ios/pip/THEOplayerRCTPipControlsManager.swift +9 -12
  39. package/ios/theoAds/THEOplayerRCTTHEOAdsAPI.swift +16 -18
  40. package/ios/theolive/THEOplayerRCTTHEOliveAPI.swift +14 -14
  41. package/lib/commonjs/api/error/ContentProtectionError.js +2 -0
  42. package/lib/commonjs/api/error/ContentProtectionError.js.map +1 -0
  43. package/lib/commonjs/api/error/barrel.js +11 -0
  44. package/lib/commonjs/api/error/barrel.js.map +1 -1
  45. package/lib/commonjs/api/event/PlayerEvent.js +16 -0
  46. package/lib/commonjs/api/event/PlayerEvent.js.map +1 -1
  47. package/lib/commonjs/api/media/MediaControlAPI.js +14 -0
  48. package/lib/commonjs/api/media/MediaControlAPI.js.map +1 -0
  49. package/lib/commonjs/api/media/barrel.js +11 -0
  50. package/lib/commonjs/api/media/barrel.js.map +1 -1
  51. package/lib/commonjs/api/player/PlayerEventMap.js +2 -0
  52. package/lib/commonjs/api/player/PlayerEventMap.js.map +1 -1
  53. package/lib/commonjs/api/player/THEOplayer.js.map +1 -1
  54. package/lib/commonjs/internal/THEOplayerView.js +8 -0
  55. package/lib/commonjs/internal/THEOplayerView.js.map +1 -1
  56. package/lib/commonjs/internal/adapter/THEOplayerAdapter.js +6 -0
  57. package/lib/commonjs/internal/adapter/THEOplayerAdapter.js.map +1 -1
  58. package/lib/commonjs/internal/adapter/THEOplayerWebAdapter.js +9 -9
  59. package/lib/commonjs/internal/adapter/THEOplayerWebAdapter.js.map +1 -1
  60. package/lib/commonjs/internal/adapter/WebEventForwarder.js +27 -0
  61. package/lib/commonjs/internal/adapter/WebEventForwarder.js.map +1 -1
  62. package/lib/commonjs/internal/adapter/event/PlayerEvents.js +14 -1
  63. package/lib/commonjs/internal/adapter/event/PlayerEvents.js.map +1 -1
  64. package/lib/commonjs/internal/adapter/media/MediaControlNativeAdapter.js +42 -0
  65. package/lib/commonjs/internal/adapter/media/MediaControlNativeAdapter.js.map +1 -0
  66. package/lib/commonjs/internal/adapter/media/MediaControlWebAdapter.js +32 -0
  67. package/lib/commonjs/internal/adapter/media/MediaControlWebAdapter.js.map +1 -0
  68. package/lib/commonjs/internal/adapter/web/WebMediaSession.js +78 -16
  69. package/lib/commonjs/internal/adapter/web/WebMediaSession.js.map +1 -1
  70. package/lib/commonjs/manifest.json +1 -1
  71. package/lib/module/api/error/ContentProtectionError.js +2 -0
  72. package/lib/module/api/error/ContentProtectionError.js.map +1 -0
  73. package/lib/module/api/error/barrel.js +1 -0
  74. package/lib/module/api/error/barrel.js.map +1 -1
  75. package/lib/module/api/event/PlayerEvent.js +18 -0
  76. package/lib/module/api/event/PlayerEvent.js.map +1 -1
  77. package/lib/module/api/media/MediaControlAPI.js +10 -0
  78. package/lib/module/api/media/MediaControlAPI.js.map +1 -0
  79. package/lib/module/api/media/barrel.js +1 -0
  80. package/lib/module/api/media/barrel.js.map +1 -1
  81. package/lib/module/api/player/PlayerEventMap.js +2 -0
  82. package/lib/module/api/player/PlayerEventMap.js.map +1 -1
  83. package/lib/module/api/player/THEOplayer.js.map +1 -1
  84. package/lib/module/internal/THEOplayerView.js +9 -1
  85. package/lib/module/internal/THEOplayerView.js.map +1 -1
  86. package/lib/module/internal/adapter/THEOplayerAdapter.js +6 -0
  87. package/lib/module/internal/adapter/THEOplayerAdapter.js.map +1 -1
  88. package/lib/module/internal/adapter/THEOplayerWebAdapter.js +9 -9
  89. package/lib/module/internal/adapter/THEOplayerWebAdapter.js.map +1 -1
  90. package/lib/module/internal/adapter/WebEventForwarder.js +28 -1
  91. package/lib/module/internal/adapter/WebEventForwarder.js.map +1 -1
  92. package/lib/module/internal/adapter/event/PlayerEvents.js +11 -0
  93. package/lib/module/internal/adapter/event/PlayerEvents.js.map +1 -1
  94. package/lib/module/internal/adapter/media/MediaControlNativeAdapter.js +37 -0
  95. package/lib/module/internal/adapter/media/MediaControlNativeAdapter.js.map +1 -0
  96. package/lib/module/internal/adapter/media/MediaControlWebAdapter.js +27 -0
  97. package/lib/module/internal/adapter/media/MediaControlWebAdapter.js.map +1 -0
  98. package/lib/module/internal/adapter/web/WebMediaSession.js +78 -16
  99. package/lib/module/internal/adapter/web/WebMediaSession.js.map +1 -1
  100. package/lib/module/manifest.json +1 -1
  101. package/lib/typescript/api/error/ContentProtectionError.d.ts +53 -0
  102. package/lib/typescript/api/error/ContentProtectionError.d.ts.map +1 -0
  103. package/lib/typescript/api/error/barrel.d.ts +1 -0
  104. package/lib/typescript/api/error/barrel.d.ts.map +1 -1
  105. package/lib/typescript/api/event/PlayerEvent.d.ts +24 -1
  106. package/lib/typescript/api/event/PlayerEvent.d.ts.map +1 -1
  107. package/lib/typescript/api/media/MediaControlAPI.d.ts +30 -0
  108. package/lib/typescript/api/media/MediaControlAPI.d.ts.map +1 -0
  109. package/lib/typescript/api/media/MediaControlConfiguration.d.ts +5 -1
  110. package/lib/typescript/api/media/MediaControlConfiguration.d.ts.map +1 -1
  111. package/lib/typescript/api/media/barrel.d.ts +1 -0
  112. package/lib/typescript/api/media/barrel.d.ts.map +1 -1
  113. package/lib/typescript/api/player/PlayerEventMap.d.ts +12 -2
  114. package/lib/typescript/api/player/PlayerEventMap.d.ts.map +1 -1
  115. package/lib/typescript/api/player/THEOplayer.d.ts +5 -0
  116. package/lib/typescript/api/player/THEOplayer.d.ts.map +1 -1
  117. package/lib/typescript/internal/THEOplayerView.d.ts +2 -0
  118. package/lib/typescript/internal/THEOplayerView.d.ts.map +1 -1
  119. package/lib/typescript/internal/adapter/THEOplayerAdapter.d.ts +3 -1
  120. package/lib/typescript/internal/adapter/THEOplayerAdapter.d.ts.map +1 -1
  121. package/lib/typescript/internal/adapter/THEOplayerWebAdapter.d.ts +3 -2
  122. package/lib/typescript/internal/adapter/THEOplayerWebAdapter.d.ts.map +1 -1
  123. package/lib/typescript/internal/adapter/WebEventForwarder.d.ts +2 -0
  124. package/lib/typescript/internal/adapter/WebEventForwarder.d.ts.map +1 -1
  125. package/lib/typescript/internal/adapter/event/PlayerEvents.d.ts +8 -1
  126. package/lib/typescript/internal/adapter/event/PlayerEvents.d.ts.map +1 -1
  127. package/lib/typescript/internal/adapter/event/native/NativePlayerEvent.d.ts +5 -1
  128. package/lib/typescript/internal/adapter/event/native/NativePlayerEvent.d.ts.map +1 -1
  129. package/lib/typescript/internal/adapter/media/MediaControlNativeAdapter.d.ts +12 -0
  130. package/lib/typescript/internal/adapter/media/MediaControlNativeAdapter.d.ts.map +1 -0
  131. package/lib/typescript/internal/adapter/media/MediaControlWebAdapter.d.ts +14 -0
  132. package/lib/typescript/internal/adapter/media/MediaControlWebAdapter.d.ts.map +1 -0
  133. package/lib/typescript/internal/adapter/web/WebMediaSession.d.ts +10 -3
  134. package/lib/typescript/internal/adapter/web/WebMediaSession.d.ts.map +1 -1
  135. package/package.json +3 -3
  136. package/react-native-theoplayer.podspec +1 -1
  137. package/src/api/error/ContentProtectionError.ts +58 -0
  138. package/src/api/error/barrel.ts +1 -0
  139. package/src/api/event/PlayerEvent.ts +26 -1
  140. package/src/api/media/MediaControlAPI.ts +33 -0
  141. package/src/api/media/MediaControlConfiguration.ts +5 -1
  142. package/src/api/media/barrel.ts +1 -0
  143. package/src/api/player/PlayerEventMap.ts +14 -0
  144. package/src/api/player/THEOplayer.ts +6 -0
  145. package/src/internal/THEOplayerView.tsx +16 -0
  146. package/src/internal/adapter/THEOplayerAdapter.ts +9 -0
  147. package/src/internal/adapter/THEOplayerWebAdapter.ts +12 -9
  148. package/src/internal/adapter/WebEventForwarder.ts +26 -0
  149. package/src/internal/adapter/event/PlayerEvents.ts +18 -0
  150. package/src/internal/adapter/event/native/NativePlayerEvent.ts +7 -0
  151. package/src/internal/adapter/media/MediaControlNativeAdapter.ts +38 -0
  152. package/src/internal/adapter/media/MediaControlWebAdapter.ts +28 -0
  153. package/src/internal/adapter/web/WebMediaSession.ts +85 -21
  154. package/src/manifest.json +1 -1
  155. package/android/src/main/java/com/theoplayer/media/MediaQueueNavigator.kt +0 -33
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-theoplayer",
3
- "version": "11.4.1",
3
+ "version": "11.6.0",
4
4
  "description": "A THEOplayer video component for react-native.",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -58,7 +58,7 @@
58
58
  "devDependencies": {
59
59
  "@eslint/js": "^9.13.0",
60
60
  "@expo/config-plugins": "^10.0.2",
61
- "@react-native/eslint-config": "^0.84.1",
61
+ "@react-native/eslint-config": "^0.86.2",
62
62
  "@types/react": "^19.2.14",
63
63
  "eslint": "^8.57.1",
64
64
  "eslint-config-prettier": "^9.1.0",
@@ -68,7 +68,7 @@
68
68
  "pod-install": "^0.1.39",
69
69
  "prettier": "^3.5.3",
70
70
  "react": "^19.2.3",
71
- "react-native": "^0.84.1",
71
+ "react-native": "^0.86.2",
72
72
  "react-native-builder-bob": "^0.39.1",
73
73
  "theoplayer": "^11.4.0",
74
74
  "typedoc": "^0.25.13",
@@ -35,7 +35,7 @@ Pod::Spec.new do |s|
35
35
  s.platforms = { :ios => "15.0", :tvos => "15.0" }
36
36
  s.source = { :git => "https://www.theoplayer.com/.git", :tag => "#{s.version}" }
37
37
 
38
- s.source_files = 'ios/*.{h,m,swift}', 'ios/ads/*.swift', 'ios/casting/*.swift', 'ios/contentprotection/*.swift', 'ios/pip/*.swift', 'ios/backgroundAudio/*.swift', 'ios/cache/*.swift', 'ios/sideloadedMetadata/*.swift', 'ios/eventBroadcasting/*.swift' , 'ios/ui/*.swift', 'ios/presentationMode/*.swift', 'ios/viewController/*.swift', 'ios/THEOlive/*.swift', 'ios/THEOads/*.swift', 'ios/millicast/*.swift', 'ios/cmcd/*.swift'
38
+ s.source_files = 'ios/*.{h,m,swift}', 'ios/ads/*.swift', 'ios/casting/*.swift', 'ios/contentprotection/*.swift', 'ios/pip/*.swift', 'ios/backgroundAudio/*.swift', 'ios/cache/*.swift', 'ios/sideloadedMetadata/*.swift', 'ios/eventBroadcasting/*.swift' , 'ios/ui/*.swift', 'ios/presentationMode/*.swift', 'ios/viewController/*.swift', 'ios/THEOlive/*.swift', 'ios/THEOads/*.swift', 'ios/millicast/*.swift', 'ios/cmcd/*.swift', 'ios/mediaControl/*.swift'
39
39
  s.resources = ['ios/*.css']
40
40
 
41
41
  # ReactNative Dependency
@@ -0,0 +1,58 @@
1
+ /**
2
+ * An error related to content protection.
3
+ *
4
+ * @category Errors
5
+ * @category Content Protection
6
+ * @public
7
+ */
8
+ export interface ContentProtectionErrorObject {
9
+ /**
10
+ * The error code.
11
+ */
12
+ readonly errorCode: string;
13
+
14
+ /**
15
+ * The error message.
16
+ */
17
+ readonly errorMessage: string;
18
+
19
+ /**
20
+ * The URL that was used in the request.
21
+ *
22
+ * @remarks
23
+ * Only available for certificate or license request errors.
24
+ */
25
+ readonly url?: string;
26
+
27
+ /**
28
+ * The status code from the HTTP response.
29
+ *
30
+ * @remarks
31
+ * Only available for certificate or license request errors.
32
+ */
33
+ readonly status?: number;
34
+
35
+ /**
36
+ * The status text from the HTTP response.
37
+ *
38
+ * @remarks
39
+ * Only available for certificate or license request errors.
40
+ */
41
+ readonly statusText?: string;
42
+
43
+ /**
44
+ * The body contained in the HTTP response.
45
+ *
46
+ * @remarks
47
+ * Only available for certificate or license request errors.
48
+ */
49
+ readonly response?: string;
50
+
51
+ /**
52
+ * The internal error code from the CDM.
53
+ *
54
+ * @remarks
55
+ * Only available for internal CDM errors.
56
+ */
57
+ readonly systemCode?: number;
58
+ }
@@ -1,2 +1,3 @@
1
1
  export * from './PlayerError';
2
2
  export * from './ChromecastError';
3
+ export * from './ContentProtectionError';
@@ -1,4 +1,4 @@
1
- import type { MediaTrack, PlayerError, PlayerEventType, PresentationMode, TextTrack, TypedSource } from 'react-native-theoplayer';
1
+ import type { MediaTrack, PlayerError, PlayerEventType, PresentationMode, TextTrack, TypedSource, ContentProtectionErrorObject } from 'react-native-theoplayer';
2
2
  import type { TimeRange } from '../timeranges/TimeRange';
3
3
  import type { Event } from './Event';
4
4
 
@@ -297,3 +297,28 @@ export interface SeekedEvent extends Event<PlayerEventType.SEEKED> {
297
297
  */
298
298
  readonly currentTime: number;
299
299
  }
300
+
301
+ /**
302
+ * Dispatched when an error related to content protection occurs.
303
+ *
304
+ * @category Events
305
+ * @category Player
306
+ * @category Content Protection
307
+ * @public
308
+ */
309
+ export interface ContentProtectionErrorEvent extends Event<PlayerEventType.CONTENT_PROTECTION_ERROR> {
310
+ /**
311
+ * An error object containing additional information about the content protection error.
312
+ */
313
+ readonly error: ContentProtectionErrorObject;
314
+ }
315
+
316
+ /**
317
+ * Dispatched when content protection succeeds, i.e. when the key session for a media track was successfully set up.
318
+ *
319
+ * @category Events
320
+ * @category Player
321
+ * @category Content Protection
322
+ * @public
323
+ */
324
+ export type ContentProtectionSuccessEvent = Event<PlayerEventType.CONTENT_PROTECTION_SUCCESS>;
@@ -0,0 +1,33 @@
1
+ import { THEOplayer } from 'react-native-theoplayer';
2
+
3
+ export type MediaControlHandler = (player: THEOplayer) => void;
4
+
5
+ export enum MediaControlAction {
6
+ PLAY = 'play',
7
+ PAUSE = 'pause',
8
+ SKIP_TO_PREVIOUS = 'skipToPrevious',
9
+ SKIP_TO_NEXT = 'skipToNext',
10
+ }
11
+
12
+ export interface MediaControlAPI {
13
+ /**
14
+ * Sets a handler for a media control action.
15
+ *
16
+ * @param action The media control action to set the handler for.
17
+ * @param handler The handler function that will be called when the specified media control action is triggered. The handler receives the THEOplayer instance as an argument.
18
+ * Passing `undefined` removes any previously set handler for the action, restoring the player's default behaviour.
19
+ */
20
+ setHandler(action: MediaControlAction, handler: MediaControlHandler | undefined): void;
21
+
22
+ /**
23
+ * Enables or disables the media session for this player instance at runtime.
24
+ *
25
+ * @remarks
26
+ * <br/> - This overrides the {@link MediaControlConfiguration.mediaSessionEnabled} value passed at creation time.
27
+ * <br/> - When multiple players are active, this can be used to designate a single "active" player that publishes
28
+ * media metadata (e.g. Now Playing info) and responds to remote control commands, while disabling the others.
29
+ *
30
+ * @param enabled Whether the media session should be enabled for this player.
31
+ */
32
+ setEnabled(enabled: boolean): void;
33
+ }
@@ -19,7 +19,7 @@ export interface MediaControlConfiguration {
19
19
  *
20
20
  * @defaultValue `true`
21
21
  *
22
- * @platform web,android
22
+ * @platform web,android,ios
23
23
  */
24
24
  readonly mediaSessionEnabled?: boolean;
25
25
 
@@ -44,6 +44,8 @@ export interface MediaControlConfiguration {
44
44
  * @defaultValue `false`
45
45
  *
46
46
  * @platform ios,android
47
+ *
48
+ * @deprecated Use {@link MediaControlAPI} to handle `skipToPrevious` and `skipToNext` actions instead.
47
49
  */
48
50
  readonly convertSkipToSeek?: boolean;
49
51
 
@@ -63,6 +65,8 @@ export interface MediaControlConfiguration {
63
65
  * @defaultValue `false`
64
66
  *
65
67
  * @platform ios,android
68
+ *
69
+ * @deprecated Use {@link MediaControlAPI} to handle `play` action and seek to the live edge instead.
66
70
  */
67
71
  readonly seekToLiveOnResume?: boolean;
68
72
  }
@@ -1 +1,2 @@
1
1
  export * from './MediaControlConfiguration';
2
+ export * from './MediaControlAPI';
@@ -1,5 +1,7 @@
1
1
  import type { Event } from '../event/Event';
2
2
  import type {
3
+ ContentProtectionErrorEvent,
4
+ ContentProtectionSuccessEvent,
3
5
  CurrentSourceChangeEvent,
4
6
  DimensionChangeEvent,
5
7
  DurationChangeEvent,
@@ -63,6 +65,8 @@ export enum PlayerEventType {
63
65
  DESTROY = 'destroy',
64
66
  DIMENSION_CHANGE = 'dimensionchange',
65
67
  VIDEO_RESIZE = 'videoresize',
68
+ CONTENT_PROTECTION_ERROR = 'contentprotectionerror',
69
+ CONTENT_PROTECTION_SUCCESS = 'contentprotectionsuccess',
66
70
  }
67
71
 
68
72
  /**
@@ -242,4 +246,14 @@ export interface PlayerEventMap {
242
246
  * Dispatched when the video size changes.
243
247
  */
244
248
  [PlayerEventType.VIDEO_RESIZE]: VideoResizeEvent;
249
+
250
+ /**
251
+ * Dispatched when an error related to content protection occurs.
252
+ */
253
+ [PlayerEventType.CONTENT_PROTECTION_ERROR]: ContentProtectionErrorEvent;
254
+
255
+ /**
256
+ * Dispatched when content protection succeeds, i.e. when the key session for a media track was successfully set up.
257
+ */
258
+ [PlayerEventType.CONTENT_PROTECTION_SUCCESS]: ContentProtectionSuccessEvent;
245
259
  }
@@ -15,6 +15,7 @@ import type { PlayerVersion } from './PlayerVersion';
15
15
  import type { EventBroadcastAPI } from '../broadcast/EventBroadcastAPI';
16
16
  import { TheoAdsAPI } from '../theoads/TheoAdsAPI';
17
17
  import { TheoLiveAPI } from '../theolive/TheoLiveAPI';
18
+ import { MediaControlAPI } from '../media/MediaControlAPI';
18
19
 
19
20
  export type PreloadType = 'none' | 'metadata' | 'auto' | '';
20
21
 
@@ -287,4 +288,9 @@ export interface THEOplayer extends EventDispatcher<PlayerEventMap> {
287
288
  * The API for THEOlive.
288
289
  */
289
290
  readonly theoLive: TheoLiveAPI;
291
+
292
+ /**
293
+ * The API for media controls.
294
+ */
295
+ readonly mediaControl?: MediaControlAPI;
290
296
  }
@@ -23,6 +23,8 @@ import {
23
23
  DefaultAirplayStateChangeEvent,
24
24
  DefaultChromecastChangeEvent,
25
25
  DefaultChromecastErrorEvent,
26
+ DefaultContentProtectionErrorEvent,
27
+ DefaultContentProtectionSuccessEvent,
26
28
  DefaultCurrentSourceChangeEvent,
27
29
  DefaultDimensionChangeEvent,
28
30
  DefaultDurationChangeEvent,
@@ -52,6 +54,8 @@ import type {
52
54
  } from './adapter/event/native/NativeTrackEvent';
53
55
  import { toMediaTrackType, toMediaTrackTypeEventType, toTextTrackEventType, toTrackListEventType } from './adapter/event/native/NativeTrackEvent';
54
56
  import {
57
+ NativeContentProtectionErrorEvent,
58
+ NativeContentProtectionSuccessEvent,
55
59
  NativeCurrentSourceChangeEvent,
56
60
  NativeDurationChangeEvent,
57
61
  NativeErrorEvent,
@@ -116,6 +120,8 @@ interface THEOplayerRCTViewProps {
116
120
  onNativeCastEvent: (event: NativeSyntheticEvent<NativeCastEvent>) => void;
117
121
  onNativePresentationModeChange: (event: NativeSyntheticEvent<NativePresentationModeChangeEvent>) => void;
118
122
  onNativeDeviceOrientationChanged: () => void;
123
+ onNativeContentProtectionError: (event: NativeSyntheticEvent<NativeContentProtectionErrorEvent>) => void;
124
+ onNativeContentProtectionSuccess: (event: NativeSyntheticEvent<NativeContentProtectionSuccessEvent>) => void;
119
125
  onNativeDimensionChange: (event: NativeSyntheticEvent<NativeDimensionChangeEvent>) => void;
120
126
  onNativeVideoResize: (event: NativeSyntheticEvent<NativeVideoResizeEvent>) => void;
121
127
  }
@@ -422,6 +428,14 @@ export class THEOplayerView extends PureComponent<React.PropsWithChildren<THEOpl
422
428
  this._facade?.dispatchEvent(new DefaultDimensionChangeEvent(width, height));
423
429
  };
424
430
 
431
+ private _onContentProtectionError = (event: NativeSyntheticEvent<NativeContentProtectionErrorEvent>) => {
432
+ this._facade?.dispatchEvent(new DefaultContentProtectionErrorEvent(event.nativeEvent.error));
433
+ };
434
+
435
+ private _onContentProtectionSuccess = (_event: NativeSyntheticEvent<NativeContentProtectionSuccessEvent>) => {
436
+ this._facade?.dispatchEvent(new DefaultContentProtectionSuccessEvent());
437
+ };
438
+
425
439
  private _onVideoResize = (event: NativeSyntheticEvent<NativeVideoResizeEvent>) => {
426
440
  this._facade?.dispatchEvent(new DefaultVideoResizeEvent(event.nativeEvent.videoWidth, event.nativeEvent.videoHeight));
427
441
  };
@@ -503,6 +517,8 @@ export class THEOplayerView extends PureComponent<React.PropsWithChildren<THEOpl
503
517
  onNativeCastEvent={this._onCastEvent}
504
518
  onNativePresentationModeChange={this._onPresentationModeChange}
505
519
  onNativeDeviceOrientationChanged={this._onDeviceOrientationChanged}
520
+ onNativeContentProtectionError={this._onContentProtectionError}
521
+ onNativeContentProtectionSuccess={this._onContentProtectionSuccess}
506
522
  onNativeDimensionChange={this._onDimensionChange}
507
523
  onNativeVideoResize={this._onVideoResize}
508
524
  />
@@ -12,6 +12,7 @@ import {
12
12
  findMediaTrackByUid,
13
13
  isVideoQuality,
14
14
  LoadedMetadataEvent,
15
+ MediaControlAPI,
15
16
  MediaTrack,
16
17
  MediaTrackEvent,
17
18
  MediaTrackEventType,
@@ -52,6 +53,7 @@ import { EventBroadcastAdapter } from './broadcast/EventBroadcastAdapter';
52
53
  import { DefaultNativePlayerState } from './DefaultNativePlayerState';
53
54
  import { THEOAdsNativeAdapter } from './theoads/THEOAdsNativeAdapter';
54
55
  import { TheoLiveNativeAdapter } from './theolive/TheoLiveNativeAdapter';
56
+ import { MediaControlNativeAdapter } from './media/MediaControlNativeAdapter';
55
57
 
56
58
  const NativePlayerModule = NativeModules.THEORCTPlayerModule;
57
59
 
@@ -64,6 +66,7 @@ export class THEOplayerAdapter extends DefaultEventDispatcher<PlayerEventMap> im
64
66
  private readonly _abrAdapter: AbrAdapter;
65
67
  private readonly _textTrackStyleAdapter: TextTrackStyleAdapter;
66
68
  private readonly _theoliveAdapter: TheoLiveNativeAdapter;
69
+ private readonly _mediaControlAdapter: MediaControlNativeAdapter;
67
70
  private _externalEventRouter: EventBroadcastAPI | undefined = undefined;
68
71
  private _playerVersion!: PlayerVersion;
69
72
 
@@ -77,6 +80,7 @@ export class THEOplayerAdapter extends DefaultEventDispatcher<PlayerEventMap> im
77
80
  this._abrAdapter = new AbrAdapter(this._view);
78
81
  this._textTrackStyleAdapter = new TextTrackStyleAdapter(this._view);
79
82
  this._theoliveAdapter = new TheoLiveNativeAdapter(this._view);
83
+ this._mediaControlAdapter = new MediaControlNativeAdapter(this);
80
84
  this.addEventListeners();
81
85
  }
82
86
 
@@ -98,6 +102,7 @@ export class THEOplayerAdapter extends DefaultEventDispatcher<PlayerEventMap> im
98
102
  }
99
103
 
100
104
  public destroy() {
105
+ this._mediaControlAdapter.destroy();
101
106
  this.clearEventListeners();
102
107
  }
103
108
 
@@ -243,6 +248,10 @@ export class THEOplayerAdapter extends DefaultEventDispatcher<PlayerEventMap> im
243
248
  return this._theoliveAdapter;
244
249
  }
245
250
 
251
+ get mediaControl(): MediaControlAPI {
252
+ return this._mediaControlAdapter;
253
+ }
254
+
246
255
  set autoplay(autoplay: boolean) {
247
256
  this._state.autoplay = autoplay;
248
257
  NativePlayerModule.setAutoplay(this._view.nativeHandle, autoplay);
@@ -7,6 +7,7 @@ import {
7
7
  CmcdConfiguration,
8
8
  CmcdTransmissionMode,
9
9
  EventBroadcastAPI,
10
+ MediaControlAPI,
10
11
  MediaTrack,
11
12
  NativeHandleType,
12
13
  PlayerConfiguration,
@@ -56,7 +57,7 @@ export class THEOplayerWebAdapter extends DefaultEventDispatcher<PlayerEventMap>
56
57
  private readonly _theoliveAdapter: TheoLiveWebAdapter;
57
58
  private _player: NativeChromelessPlayer | undefined;
58
59
  private _eventForwarder: WebEventForwarder | undefined;
59
- private _mediaSession: WebMediaSession | undefined = undefined;
60
+ private readonly _mediaSession: WebMediaSession;
60
61
  private _targetVideoQuality: number | number[] | undefined = undefined;
61
62
  private _backgroundAudioConfiguration: BackgroundAudioConfiguration = defaultBackgroundAudioConfiguration;
62
63
  private _pipConfiguration: PiPConfiguration = defaultPipConfiguration;
@@ -78,10 +79,13 @@ export class THEOplayerWebAdapter extends DefaultEventDispatcher<PlayerEventMap>
78
79
  document.addEventListener('visibilitychange', this.onVisibilityChange);
79
80
  this._player.addEventListener('dimensionchange', this.onPlayerDimensionChange);
80
81
 
81
- // Optionally create a media session connector
82
- if (config?.mediaControl?.mediaSessionEnabled !== false) {
83
- this._mediaSession = new WebMediaSession(this, player, config?.mediaControl);
84
- }
82
+ // Always create a media session connector so it can be toggled at runtime via mediaControl.setEnabled().
83
+ // The initial enabled state is derived from config.mediaControl.mediaSessionEnabled.
84
+ this._mediaSession = new WebMediaSession(this, player, config?.mediaControl);
85
+ }
86
+
87
+ get mediaControl(): MediaControlAPI {
88
+ return this._mediaSession.mediaControlAdapter;
85
89
  }
86
90
 
87
91
  get abr(): ABRConfiguration | undefined {
@@ -206,7 +210,7 @@ export class THEOplayerWebAdapter extends DefaultEventDispatcher<PlayerEventMap>
206
210
  this._backgroundAudioConfiguration = config;
207
211
 
208
212
  // Notify media session
209
- this._mediaSession?.updateMediaSession();
213
+ this._mediaSession.updateMediaSession();
210
214
  }
211
215
 
212
216
  get volume(): number {
@@ -389,10 +393,9 @@ export class THEOplayerWebAdapter extends DefaultEventDispatcher<PlayerEventMap>
389
393
  destroy(): void {
390
394
  this.dispatchEvent(new BaseEvent(PlayerEventType.DESTROY));
391
395
  this._eventForwarder?.unload();
392
- this._mediaSession?.destroy();
396
+ this._mediaSession.destroy();
393
397
  document.removeEventListener('visibilitychange', this.onVisibilityChange);
394
398
  this._eventForwarder = undefined;
395
- this._mediaSession = undefined;
396
399
  this._cmcdConnector?.destroy();
397
400
  this._cmcdConnector = undefined;
398
401
  this._player?.removeEventListener('dimensionchange', this.onPlayerDimensionChange);
@@ -416,7 +419,7 @@ export class THEOplayerWebAdapter extends DefaultEventDispatcher<PlayerEventMap>
416
419
  }
417
420
  }
418
421
  // Apply media session controls
419
- this._mediaSession?.updateMediaSession();
422
+ this._mediaSession.updateMediaSession();
420
423
  };
421
424
 
422
425
  private readonly onPlayerDimensionChange = (event: DimensionChangeEvent) => {
@@ -6,6 +6,7 @@ import type {
6
6
  CastStateChangeEvent,
7
7
  ChromecastErrorEvent,
8
8
  ChromelessPlayer,
9
+ ContentProtectionErrorEvent as NativeContentProtectionErrorEvent,
9
10
  CurrentSourceChangeEvent as NativeCurrentSourceChangeEvent,
10
11
  DimensionChangeEvent as NativeDimensionChangeEvent,
11
12
  DurationChangeEvent as NativeDurationChangeEvent,
@@ -52,6 +53,8 @@ import {
52
53
  DefaultAirplayStateChangeEvent,
53
54
  DefaultChromecastChangeEvent,
54
55
  DefaultChromecastErrorEvent,
56
+ DefaultContentProtectionErrorEvent,
57
+ DefaultContentProtectionSuccessEvent,
55
58
  DefaultCurrentSourceChangeEvent,
56
59
  DefaultDimensionChangeEvent,
57
60
  DefaultDurationChangeEvent,
@@ -112,6 +115,8 @@ export class WebEventForwarder {
112
115
  this._player.addEventListener('ratechange', this.onPlaybackRateChange);
113
116
  this._player.addEventListener('segmentnotfound', this.onSegmentNotFound);
114
117
  this._player.addEventListener('volumechange', this.onVolumeChangeEvent);
118
+ this._player.addEventListener('contentprotectionerror', this.onContentProtectionError);
119
+ this._player.addEventListener('contentprotectionsuccess', this.onContentProtectionSuccess);
115
120
  this._player.addEventListener('dimensionchange', this.onDimensionChange);
116
121
  this._player.addEventListener('resize', this.onVideoResize);
117
122
 
@@ -163,6 +168,8 @@ export class WebEventForwarder {
163
168
  this._player.removeEventListener('ratechange', this.onPlaybackRateChange);
164
169
  this._player.removeEventListener('segmentnotfound', this.onSegmentNotFound);
165
170
  this._player.removeEventListener('volumechange', this.onVolumeChangeEvent);
171
+ this._player.removeEventListener('contentprotectionerror', this.onContentProtectionError);
172
+ this._player.removeEventListener('contentprotectionsuccess', this.onContentProtectionSuccess);
166
173
  this._player.removeEventListener('dimensionchange', this.onDimensionChange);
167
174
  this._player.removeEventListener('resize', this.onVideoResize);
168
175
 
@@ -227,6 +234,25 @@ export class WebEventForwarder {
227
234
  );
228
235
  };
229
236
 
237
+ private readonly onContentProtectionError = (event: NativeContentProtectionErrorEvent) => {
238
+ const { code, message: errorMessage, url, status, statusText, response, systemCode } = event.errorObject;
239
+ this._facade.dispatchEvent(
240
+ new DefaultContentProtectionErrorEvent({
241
+ errorCode: code.toString(),
242
+ errorMessage,
243
+ url,
244
+ status,
245
+ statusText,
246
+ response,
247
+ systemCode,
248
+ }),
249
+ );
250
+ };
251
+
252
+ private readonly onContentProtectionSuccess = () => {
253
+ this._facade.dispatchEvent(new DefaultContentProtectionSuccessEvent());
254
+ };
255
+
230
256
  private readonly onProgress = () => {
231
257
  this._facade.dispatchEvent(new DefaultProgressEvent(fromTimeRanges(this._player.seekable), fromTimeRanges(this._player.buffered)));
232
258
  };
@@ -10,6 +10,9 @@ import {
10
10
  ChromecastChangeEvent,
11
11
  ChromecastError,
12
12
  ChromecastErrorEvent,
13
+ ContentProtectionErrorEvent,
14
+ ContentProtectionErrorObject,
15
+ ContentProtectionSuccessEvent,
13
16
  CurrentSourceChangeEvent,
14
17
  DimensionChangeEvent,
15
18
  DurationChangeEvent,
@@ -314,3 +317,18 @@ export class DefaultChromecastErrorEvent extends BaseEvent<PlayerEventType.CAST_
314
317
  this.subType = CastEventType.CHROMECAST_ERROR;
315
318
  }
316
319
  }
320
+
321
+ export class DefaultContentProtectionErrorEvent extends BaseEvent<PlayerEventType.CONTENT_PROTECTION_ERROR> implements ContentProtectionErrorEvent {
322
+ constructor(public readonly error: ContentProtectionErrorObject) {
323
+ super(PlayerEventType.CONTENT_PROTECTION_ERROR);
324
+ }
325
+ }
326
+
327
+ export class DefaultContentProtectionSuccessEvent
328
+ extends BaseEvent<PlayerEventType.CONTENT_PROTECTION_SUCCESS>
329
+ implements ContentProtectionSuccessEvent
330
+ {
331
+ constructor() {
332
+ super(PlayerEventType.CONTENT_PROTECTION_SUCCESS);
333
+ }
334
+ }
@@ -1,4 +1,5 @@
1
1
  import type {
2
+ ContentProtectionErrorObject,
2
3
  MediaTrack,
3
4
  PlayerError,
4
5
  PlayerVersion,
@@ -162,6 +163,12 @@ export interface NativeSegmentNotFoundEvent {
162
163
  readonly retryCount: number;
163
164
  }
164
165
 
166
+ export interface NativeContentProtectionErrorEvent {
167
+ error: ContentProtectionErrorObject;
168
+ }
169
+
170
+ export type NativeContentProtectionSuccessEvent = Record<string, never>;
171
+
165
172
  export interface NativePlayerStateEvent {
166
173
  readonly version: PlayerVersion;
167
174
 
@@ -0,0 +1,38 @@
1
+ import { THEOplayer, MediaControlAction, MediaControlAPI, MediaControlHandler } from 'react-native-theoplayer';
2
+ import { EmitterSubscription, NativeEventEmitter, NativeModules } from 'react-native';
3
+
4
+ const NativeMediaControlModule = NativeModules.THEORCTMediaControlModule;
5
+
6
+ export class MediaControlNativeAdapter implements MediaControlAPI {
7
+ private mediaControlEmitter = new NativeEventEmitter(NativeMediaControlModule);
8
+ private handlers: Map<MediaControlAction, MediaControlHandler> = new Map();
9
+ private readonly _subscription: EmitterSubscription;
10
+
11
+ constructor(private readonly _player: THEOplayer) {
12
+ this._subscription = this.mediaControlEmitter.addListener('MediaControlEvent', (event) => {
13
+ const { tag, action } = event;
14
+ if (tag === this._player.nativeHandle) {
15
+ this.handlers.get(action)?.(this._player);
16
+ }
17
+ });
18
+ }
19
+
20
+ setHandler(action: MediaControlAction, handler: MediaControlHandler | undefined): void {
21
+ if (handler === undefined) {
22
+ this.handlers.delete(action);
23
+ NativeMediaControlModule.removeHandler(this._player.nativeHandle || -1, action);
24
+ return;
25
+ }
26
+ this.handlers.set(action, handler);
27
+ NativeMediaControlModule.setHandler(this._player.nativeHandle || -1, action);
28
+ }
29
+
30
+ setEnabled(enabled: boolean): void {
31
+ NativeMediaControlModule.setEnabled(this._player.nativeHandle || -1, enabled);
32
+ }
33
+
34
+ destroy(): void {
35
+ this._subscription.remove();
36
+ this.handlers.clear();
37
+ }
38
+ }
@@ -0,0 +1,28 @@
1
+ import { MediaControlAction, MediaControlAPI, MediaControlHandler } from 'react-native-theoplayer';
2
+ import { WebMediaSession } from '../web/WebMediaSession';
3
+
4
+ export class MediaControlWebAdapter implements MediaControlAPI {
5
+ private handlers: Map<MediaControlAction, MediaControlHandler> = new Map();
6
+
7
+ constructor(private readonly mediaSession: WebMediaSession) {}
8
+
9
+ setHandler(action: MediaControlAction, handler: MediaControlHandler | undefined): void {
10
+ if (handler === undefined) {
11
+ this.handlers.delete(action);
12
+ } else {
13
+ this.handlers.set(action, handler);
14
+ }
15
+ this.mediaSession.updateMediaSession();
16
+ }
17
+
18
+ /**
19
+ * @internal Used by {@link WebMediaSession} to dispatch a media session action to the user's handler.
20
+ */
21
+ getHandler(action: MediaControlAction): MediaControlHandler | undefined {
22
+ return this.handlers.get(action);
23
+ }
24
+
25
+ setEnabled(enabled: boolean): void {
26
+ this.mediaSession.setEnabled(enabled);
27
+ }
28
+ }