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
@@ -1,6 +1,8 @@
1
1
  package com.theoplayer.media
2
2
 
3
3
  import com.facebook.react.bridge.ReadableMap
4
+ import com.theoplayer.util.getBooleanOr
5
+ import com.theoplayer.util.getDoubleOr
4
6
 
5
7
  object MediaSessionConfigAdapter {
6
8
  private const val PROP_ENABLED = "mediaSessionEnabled"
@@ -11,25 +13,26 @@ object MediaSessionConfigAdapter {
11
13
  private const val PROP_SEEK_TO_LIVE_RESUME = "seekToLiveOnResume"
12
14
 
13
15
  fun fromProps(props: ReadableMap?): MediaSessionConfig {
14
- return MediaSessionConfig().apply {
15
- if (props?.hasKey(PROP_ENABLED) == true) {
16
- mediaSessionEnabled = props.getBoolean(PROP_ENABLED)
17
- }
18
- if (props?.hasKey(PROP_SKIP_FORWARD_INTERVAL) == true) {
19
- skipForwardInterval = props.getDouble(PROP_SKIP_FORWARD_INTERVAL)
20
- }
21
- if (props?.hasKey(PROP_SKIP_BACKWARD_INTERVAL) == true) {
22
- skipBackwardInterval = props.getDouble(PROP_SKIP_BACKWARD_INTERVAL)
23
- }
24
- if (props?.hasKey(PROP_CONVERT_SKIP) == true) {
25
- convertSkipToSeek = props.getBoolean(PROP_CONVERT_SKIP)
26
- }
27
- if (props?.hasKey(PROP_ALLOW_LIVE_PLAY_PAUSE) == true) {
28
- allowLivePlayPause = props.getBoolean(PROP_ALLOW_LIVE_PLAY_PAUSE)
29
- }
30
- if (props?.hasKey(PROP_SEEK_TO_LIVE_RESUME) == true) {
31
- seekToLiveOnResume = props.getBoolean(PROP_SEEK_TO_LIVE_RESUME)
32
- }
33
- }
16
+ val defaults = MediaSessionConfig()
17
+ return MediaSessionConfig(
18
+ mediaSessionEnabled = props.getBooleanOr(PROP_ENABLED, defaults.mediaSessionEnabled),
19
+ skipForwardInterval = props.getDoubleOr(
20
+ PROP_SKIP_FORWARD_INTERVAL,
21
+ defaults.skipForwardInterval
22
+ ),
23
+ skipBackwardInterval = props.getDoubleOr(
24
+ PROP_SKIP_BACKWARD_INTERVAL,
25
+ defaults.skipBackwardInterval
26
+ ),
27
+ convertSkipToSeek = props.getBooleanOr(PROP_CONVERT_SKIP, defaults.convertSkipToSeek),
28
+ allowLivePlayPause = props.getBooleanOr(
29
+ PROP_ALLOW_LIVE_PLAY_PAUSE,
30
+ defaults.allowLivePlayPause
31
+ ),
32
+ seekToLiveOnResume = props.getBooleanOr(
33
+ PROP_SEEK_TO_LIVE_RESUME,
34
+ defaults.seekToLiveOnResume
35
+ )
36
+ )
34
37
  }
35
38
  }
@@ -20,7 +20,6 @@ import com.theoplayer.presentation.PipConfigAdapter
20
20
  import com.theoplayer.track.TextTrackStyleAdapter
21
21
  import com.theoplayer.util.ViewResolver
22
22
  import com.theoplayer.util.findReactRootView
23
- import com.theoplayer.util.getClosestParentOfType
24
23
 
25
24
  @Suppress("unused")
26
25
  @ReactModule(name = PlayerModule.NAME)
@@ -15,15 +15,16 @@ import android.util.Rational
15
15
  import android.view.ViewGroup
16
16
  import androidx.annotation.RequiresApi
17
17
  import com.facebook.react.uimanager.ThemedReactContext
18
- import com.theoplayer.BuildConfig
19
18
  import com.theoplayer.R
20
19
  import com.theoplayer.ReactTHEOplayerContext
21
- import com.theoplayer.android.api.ads.ima.GoogleImaAdEvent
22
- import com.theoplayer.android.api.ads.ima.GoogleImaAdEventType
23
20
  import com.theoplayer.android.api.event.EventListener
24
21
  import com.theoplayer.android.api.event.player.PlayerEvent
25
22
  import com.theoplayer.android.api.event.player.PlayerEventTypes
26
23
  import com.theoplayer.android.api.player.Player
24
+ import com.theoplayer.media.AvailableActionsListener
25
+ import com.theoplayer.media.MediaControlProxy
26
+ import com.theoplayer.media.MediaControlSlot
27
+ import com.theoplayer.media.MediaControlSlots
27
28
 
28
29
  private const val EXTRA_ACTION = "EXTRA_ACTION"
29
30
  private const val ACTION_MEDIA_CONTROL = "pip_media_control"
@@ -31,8 +32,9 @@ private const val ACTION_PLAY = 0
31
32
  private const val ACTION_PAUSE = ACTION_PLAY + 1
32
33
  private const val ACTION_RWD = ACTION_PLAY + 2
33
34
  private const val ACTION_FFD = ACTION_PLAY + 3
35
+ private const val ACTION_SKIP_TO_PREV = ACTION_PLAY + 4
36
+ private const val ACTION_SKIP_TO_NEXT = ACTION_PLAY + 5
34
37
  private const val ACTION_IGNORE = ACTION_PLAY + 999
35
- private const val SKIP_TIME = 15
36
38
  private const val NO_ICON = -1
37
39
 
38
40
  private val PIP_ASPECT_RATIO_DEFAULT = Rational(16, 9)
@@ -45,38 +47,37 @@ class PipUtils(
45
47
  ) {
46
48
 
47
49
  private var enabled: Boolean = false
48
- private var onPlayerAction: EventListener<PlayerEvent<*>>
49
- private var onAdAction: EventListener<GoogleImaAdEvent>
50
+
51
+ // The play/pause button reflects the playback state.
52
+ private val onPlayerAction = EventListener<PlayerEvent<*>> { updatePipParams() }
50
53
  private val playerEvents = listOf(PlayerEventTypes.PLAY, PlayerEventTypes.PAUSE)
51
- private var adEvents = listOf<GoogleImaAdEventType>()
54
+
55
+ // Which actions are available is decided by the MediaControlProxy, which notifies us whenever that
56
+ // changes, for example when switching between content and ads, or when the stream turns out to be live.
57
+ private val onAvailableActionsChanged = AvailableActionsListener { updatePipParams() }
58
+
52
59
  private val broadcastReceiver: BroadcastReceiver = buildBroadcastReceiver()
53
60
 
61
+ // The player the listeners are registered on, so they are removed from that same instance.
62
+ private var listeningPlayer: Player? = null
63
+
54
64
  private val player: Player
55
65
  get() = viewCtx.player
56
66
 
57
- init {
58
- onPlayerAction = EventListener {
59
- updatePipParams()
60
- }
61
- onAdAction = EventListener {
62
- updatePipParams()
63
- }
64
- if (BuildConfig.EXTENSION_GOOGLE_IMA) {
65
- adEvents = listOf(GoogleImaAdEventType.STARTED, GoogleImaAdEventType.CONTENT_RESUME_REQUESTED)
66
- }
67
- }
67
+ private val mediaControlProxy: MediaControlProxy
68
+ get() = viewCtx.mediaControlProxy
68
69
 
69
70
  @SuppressLint("UnspecifiedRegisterReceiverFlag")
70
71
  fun enable() {
71
72
  if (enabled) {
72
73
  return
73
74
  }
74
- playerEvents.forEach { action ->
75
- player.addEventListener(action, onPlayerAction)
76
- }
77
- adEvents.forEach { action ->
78
- player.ads.addEventListener(action, onAdAction)
75
+ listeningPlayer = player.also { player ->
76
+ playerEvents.forEach { action ->
77
+ player.addEventListener(action, onPlayerAction)
78
+ }
79
79
  }
80
+ mediaControlProxy.addAvailableActionsListener(onAvailableActionsChanged)
80
81
 
81
82
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
82
83
  reactContext.currentActivity?.registerReceiver(
@@ -97,12 +98,13 @@ class PipUtils(
97
98
  if (!enabled) {
98
99
  return
99
100
  }
100
- playerEvents.forEach { action ->
101
- player.removeEventListener(action, onPlayerAction)
102
- }
103
- adEvents.forEach { action ->
104
- player.ads.removeEventListener(action, onAdAction)
101
+ listeningPlayer?.let { player ->
102
+ playerEvents.forEach { action ->
103
+ player.removeEventListener(action, onPlayerAction)
104
+ }
105
105
  }
106
+ listeningPlayer = null
107
+ mediaControlProxy.removeAvailableActionsListener(onAvailableActionsChanged)
106
108
  try {
107
109
  reactContext.currentActivity?.unregisterReceiver(broadcastReceiver)
108
110
  } catch (ignore: IllegalArgumentException) { /*ignore*/
@@ -114,60 +116,66 @@ class PipUtils(
114
116
  disable()
115
117
  }
116
118
 
119
+ /**
120
+ * Builds the PiP actions for the media controls that the proxy reports as available.
121
+ */
117
122
  @RequiresApi(Build.VERSION_CODES.O)
118
- fun buildPipActions(
119
- paused: Boolean,
120
- enablePlayPause: Boolean,
121
- enableTrickPlay: Boolean
122
- ): List<RemoteAction> {
123
- return mutableListOf<RemoteAction>().apply {
124
-
125
- // Trick-play: Rewind
126
- if (enableTrickPlay) {
127
- add(
128
- buildRemoteAction(
129
- ACTION_RWD,
130
- R.drawable.ic_rewind,
131
- R.string.rewind,
132
- R.string.rewind_description
133
- )
123
+ private fun buildPipActions(paused: Boolean, slots: MediaControlSlots): List<RemoteAction> {
124
+ return listOfNotNull(
125
+ slots.leading?.let { remoteAction(it) },
126
+ // Always add the play/pause button, but send an ACTION_IGNORE and make it invisible if disabled.
127
+ // If no RemoteActions are added, MediaSession takes over the UI.
128
+ if (paused) {
129
+ buildRemoteAction(
130
+ ACTION_PLAY,
131
+ R.drawable.ic_play,
132
+ R.string.play,
133
+ R.string.play_description,
134
+ slots.playPauseEnabled
134
135
  )
135
- }
136
+ } else {
137
+ buildRemoteAction(
138
+ ACTION_PAUSE,
139
+ R.drawable.ic_pause,
140
+ R.string.play,
141
+ R.string.pause_description,
142
+ slots.playPauseEnabled
143
+ )
144
+ },
145
+ slots.trailing?.let { remoteAction(it) }
146
+ )
147
+ }
136
148
 
137
- // Play/pause
138
- // Always add this button, but send an ACTION_IGNORE and make invisible if disabled.
139
- // If no RemoteActions are added, MediaSession takes over the UI.
140
- add(
141
- if (paused) {
142
- buildRemoteAction(
143
- ACTION_PLAY,
144
- R.drawable.ic_play,
145
- R.string.play,
146
- R.string.play_description,
147
- enablePlayPause
148
- )
149
- } else {
150
- buildRemoteAction(
151
- ACTION_PAUSE,
152
- R.drawable.ic_pause,
153
- R.string.play,
154
- R.string.pause_description,
155
- enablePlayPause
156
- )
157
- }
149
+ @RequiresApi(Build.VERSION_CODES.O)
150
+ private fun remoteAction(slot: MediaControlSlot): RemoteAction {
151
+ return when (slot) {
152
+ MediaControlSlot.SKIP_TO_PREVIOUS -> buildRemoteAction(
153
+ ACTION_SKIP_TO_PREV,
154
+ R.drawable.ic_prev,
155
+ R.string.skip_to_previous,
156
+ R.string.skip_to_previous_description
158
157
  )
159
158
 
160
- // Trick-play: Fast Forward
161
- if (enableTrickPlay) {
162
- add(
163
- buildRemoteAction(
164
- ACTION_FFD,
165
- R.drawable.ic_fast_forward,
166
- R.string.fast_forward,
167
- R.string.fast_forward_description
168
- )
169
- )
170
- }
159
+ MediaControlSlot.SKIP_TO_NEXT -> buildRemoteAction(
160
+ ACTION_SKIP_TO_NEXT,
161
+ R.drawable.ic_next,
162
+ R.string.skip_to_next,
163
+ R.string.skip_to_next_description
164
+ )
165
+
166
+ MediaControlSlot.REWIND -> buildRemoteAction(
167
+ ACTION_RWD,
168
+ R.drawable.ic_rewind,
169
+ R.string.rewind,
170
+ R.string.rewind_description
171
+ )
172
+
173
+ MediaControlSlot.FAST_FORWARD -> buildRemoteAction(
174
+ ACTION_FFD,
175
+ R.drawable.ic_fast_forward,
176
+ R.string.fast_forward,
177
+ R.string.fast_forward_description
178
+ )
171
179
  }
172
180
  }
173
181
 
@@ -198,21 +206,13 @@ class PipUtils(
198
206
 
199
207
  @RequiresApi(Build.VERSION_CODES.O)
200
208
  fun getPipParams(): PictureInPictureParams {
201
- val view = viewCtx.playerView
202
- val player = view.player
203
- val visibleRect = getContentViewRect(view)
204
- val isAd = player.ads.isPlaying
205
- val isLive = player.duration.isInfinite()
206
- val enablePlayPause = !isAd
207
- val enableTrickPlay = !isAd && !isLive
209
+ val visibleRect = getContentViewRect(viewCtx.playerView)
208
210
 
209
211
  return PictureInPictureParams.Builder()
210
212
  .setSourceRectHint(visibleRect)
211
213
  // Must be between 2.39:1 and 1:2.39 (inclusive)
212
- .setAspectRatio(getSafeAspectRatio(view.player.videoWidth, view.player.videoHeight))
213
- .setActions(
214
- buildPipActions(player.isPaused, enablePlayPause, enableTrickPlay)
215
- )
214
+ .setAspectRatio(getSafeAspectRatio(player.videoWidth, player.videoHeight))
215
+ .setActions(buildPipActions(player.isPaused, mediaControlProxy.controlSlots))
216
216
  .build()
217
217
  }
218
218
 
@@ -227,11 +227,15 @@ class PipUtils(
227
227
  @RequiresApi(Build.VERSION_CODES.O)
228
228
  override fun onReceive(context: Context?, intent: Intent?) {
229
229
  intent?.getIntExtra(EXTRA_ACTION, -1)?.let { action ->
230
- when (action) {
231
- ACTION_PLAY -> player.play()
232
- ACTION_PAUSE -> player.pause()
233
- ACTION_FFD -> player.currentTime += SKIP_TIME
234
- ACTION_RWD -> player.currentTime -= SKIP_TIME
230
+ viewCtx.mediaControlProxy.apply {
231
+ when (action) {
232
+ ACTION_PLAY -> onPlay()
233
+ ACTION_PAUSE -> onPause()
234
+ ACTION_FFD -> onFastForward()
235
+ ACTION_RWD -> onRewind()
236
+ ACTION_SKIP_TO_NEXT -> onSkipToNext(player)
237
+ ACTION_SKIP_TO_PREV -> onSkipToPrevious(player)
238
+ }
235
239
  }
236
240
  reactContext.currentActivity?.setPictureInPictureParams(getPipParams())
237
241
  }
@@ -260,6 +264,7 @@ class PipUtils(
260
264
  // the NO_ICON causes a System UI crash.
261
265
  Build.VERSION.SDK_INT in Build.VERSION_CODES.O..Build.VERSION_CODES.R ->
262
266
  android.R.drawable.screen_background_light_transparent
267
+
263
268
  else -> NO_ICON
264
269
  }
265
270
  )
@@ -8,3 +8,17 @@ import com.facebook.react.bridge.ReadableMap
8
8
  fun ReadableMap.getBooleanOrNull(name: String): Boolean? {
9
9
  return if (hasKey(name)) getBoolean(name) else null
10
10
  }
11
+
12
+ /**
13
+ * Gets a boolean value from the map, or [default] if the map or the key does not exist.
14
+ */
15
+ fun ReadableMap?.getBooleanOr(name: String, default: Boolean): Boolean {
16
+ return if (this?.hasKey(name) == true) getBoolean(name) else default
17
+ }
18
+
19
+ /**
20
+ * Gets a double value from the map, or [default] if the map or the key does not exist.
21
+ */
22
+ fun ReadableMap?.getDoubleOr(name: String, default: Double): Double {
23
+ return if (this?.hasKey(name) == true) getDouble(name) else default
24
+ }
@@ -0,0 +1,9 @@
1
+ <vector xmlns:android="http://schemas.android.com/apk/res/android"
2
+ android:width="24dp"
3
+ android:height="24dp"
4
+ android:viewportWidth="960"
5
+ android:viewportHeight="960">
6
+ <path
7
+ android:pathData="M660,720v-480h80v480h-80ZM220,720v-480l360,240 -360,240Z"
8
+ android:fillColor="#000000"/>
9
+ </vector>
@@ -0,0 +1,9 @@
1
+ <vector xmlns:android="http://schemas.android.com/apk/res/android"
2
+ android:width="24dp"
3
+ android:height="24dp"
4
+ android:viewportWidth="960"
5
+ android:viewportHeight="960">
6
+ <path
7
+ android:pathData="M220,720v-480h80v480h-80ZM740,720L380,480l360,-240v480Z"
8
+ android:fillColor="#000000"/>
9
+ </vector>
@@ -8,6 +8,10 @@
8
8
  <string name="fast_forward_description">Fast Forward video</string>
9
9
  <string name="rewind">Rewind</string>
10
10
  <string name="rewind_description">Rewind video</string>
11
+ <string name="skip_to_previous">Skip to Previous</string>
12
+ <string name="skip_to_previous_description">Skip to previous playlist item</string>
13
+ <string name="skip_to_next">Skip to Next</string>
14
+ <string name="skip_to_next_description">Skip to next playlist item</string>
11
15
 
12
16
  <string name="background_playback_service_description">THEOplayer service providing background playback.</string>
13
17
  <string name="notification_channel_id">theoplayer_default_channel</string>
@@ -0,0 +1,59 @@
1
+ // RCTBridgeModule+ViewHelpers.swift
2
+
3
+ import Foundation
4
+ import THEOplayerSDK
5
+
6
+ extension RCTBridgeModule {
7
+
8
+ /// Resolves the THEOplayerRCTView for the given react tag on the main thread and invokes the action.
9
+ /// If the view cannot be resolved, the optional onFailure callback is invoked instead.
10
+ func withView(_ node: NSNumber, _ action: @escaping (THEOplayerRCTView) -> Void, onFailure: (() -> Void)? = nil) {
11
+ DispatchQueue.main.async { [self] in
12
+ if let bridge = self.bridge as? RCTBridge,
13
+ let theView = bridge.uiManager.view(forReactTag: node) as? THEOplayerRCTView {
14
+ action(theView)
15
+ } else {
16
+ onFailure?()
17
+ }
18
+ }
19
+ }
20
+
21
+ /// Resolves the THEOplayerRCTView and its THEOplayer instance for the given react tag on the main thread.
22
+ /// If the view or player cannot be resolved, the optional onFailure callback is invoked instead.
23
+ func withViewAndPlayer(_ node: NSNumber, _ action: @escaping (THEOplayerRCTView, THEOplayer) -> Void, onFailure: (() -> Void)? = nil) {
24
+ withView(node, { theView in
25
+ if let player = theView.player {
26
+ action(theView, player)
27
+ } else {
28
+ onFailure?()
29
+ }
30
+ }, onFailure: onFailure)
31
+ }
32
+
33
+ /// Resolves the THEOplayerRCTView and its Ads module for the given react tag on the main thread.
34
+ /// If the view or ads module cannot be resolved, the optional onFailure callback is invoked instead.
35
+ func withViewAndAds(_ node: NSNumber, _ action: @escaping (THEOplayerRCTView, Ads) -> Void, onFailure: (() -> Void)? = nil) {
36
+ withView(node, { theView in
37
+ if let ads = theView.ads() {
38
+ action(theView, ads)
39
+ } else {
40
+ onFailure?()
41
+ }
42
+ }, onFailure: onFailure)
43
+ }
44
+
45
+ #if os(iOS)
46
+ /// Resolves the THEOplayerRCTView and its Cast module for the given react tag on the main thread.
47
+ /// If the view or cast module cannot be resolved, the optional onFailure callback is invoked instead.
48
+ func withViewAndCast(_ node: NSNumber, _ action: @escaping (THEOplayerRCTView, Cast) -> Void, onFailure: (() -> Void)? = nil) {
49
+ withView(node, { theView in
50
+ if let cast = theView.cast() {
51
+ action(theView, cast)
52
+ } else {
53
+ onFailure?()
54
+ }
55
+ }, onFailure: onFailure)
56
+ }
57
+ #endif
58
+
59
+ }
@@ -47,6 +47,8 @@ RCT_EXPORT_VIEW_PROPERTY(onNativeMediaTrackEvent, RCTDirectEventBlock);
47
47
  RCT_EXPORT_VIEW_PROPERTY(onNativeDeviceOrientationChanged, RCTDirectEventBlock);
48
48
  RCT_EXPORT_VIEW_PROPERTY(onNativePlayerReady, RCTDirectEventBlock);
49
49
  RCT_EXPORT_VIEW_PROPERTY(onNativePresentationModeChange, RCTDirectEventBlock);
50
+ RCT_EXPORT_VIEW_PROPERTY(onNativeContentProtectionError, RCTDirectEventBlock);
51
+ RCT_EXPORT_VIEW_PROPERTY(onNativeContentProtectionSuccess, RCTDirectEventBlock);
50
52
  RCT_EXPORT_VIEW_PROPERTY(onNativeDimensionChange, RCTDirectEventBlock);
51
53
  RCT_EXPORT_VIEW_PROPERTY(onNativeVideoResize, RCTDirectEventBlock);
52
54
  RCT_EXPORT_VIEW_PROPERTY(onNativeAdEvent, RCTDirectEventBlock);
@@ -315,3 +317,18 @@ RCT_EXTERN_METHOD(setAdTagParameters:(nonnull NSNumber *)node
315
317
 
316
318
  @end
317
319
 
320
+ // ----------------------------------------------------------------------------
321
+ // MediaControl Module
322
+ // ----------------------------------------------------------------------------
323
+ @interface RCT_EXTERN_REMAP_MODULE(THEORCTMediaControlModule, THEOplayerRCTMediaControlAPI, RCTEventEmitter)
324
+
325
+ RCT_EXTERN_METHOD(setHandler:(nonnull NSNumber *)node
326
+ action:(nonnull NSString *)action)
327
+
328
+ RCT_EXTERN_METHOD(removeHandler:(nonnull NSNumber *)node
329
+ action:(nonnull NSString *)action)
330
+
331
+ RCT_EXTERN_METHOD(setEnabled:(nonnull NSNumber *)node
332
+ enabled:(BOOL)enabled)
333
+
334
+ @end
@@ -60,3 +60,6 @@ let DEBUG_PRESENTATIONMODES = DEBUG && false
60
60
  // Debug flag to monitor App state changes
61
61
  let DEBUG_APPSTATE = DEBUG && false
62
62
 
63
+ // Debug flag to monitor mediacontrol API usage
64
+ let DEBUG_MEDIA_CONTROL_API = DEBUG && false
65
+
@@ -30,6 +30,8 @@ public class THEOplayerRCTMainEventHandler {
30
30
  var onNativeRateChange: RCTDirectEventBlock?
31
31
  var onNativeWaiting: RCTDirectEventBlock?
32
32
  var onNativeCanPlay: RCTDirectEventBlock?
33
+ var onNativeContentProtectionError: RCTDirectEventBlock?
34
+ var onNativeContentProtectionSuccess: RCTDirectEventBlock?
33
35
  var onNativeDimensionChange: RCTDirectEventBlock?
34
36
  var onNativeVideoResize: RCTDirectEventBlock?
35
37
 
@@ -54,6 +56,7 @@ public class THEOplayerRCTMainEventHandler {
54
56
  private var rateChangeListener: EventListener?
55
57
  private var waitingListener: EventListener?
56
58
  private var canPlayListener: EventListener?
59
+ private var contentProtectionSuccessListener: EventListener?
57
60
  private var videoResizeListener: EventListener?
58
61
 
59
62
  // MARK: player observer
@@ -278,6 +281,15 @@ public class THEOplayerRCTMainEventHandler {
278
281
  }
279
282
  if DEBUG_EVENTHANDLER { PrintUtils.printLog(logText: "[NATIVE] Error listener attached to THEOplayer") }
280
283
 
284
+ // CONTENT_PROTECTION_SUCCESS
285
+ self.contentProtectionSuccessListener = player.addEventListener(type: PlayerEventTypes.CONTENT_PROTECTION_SUCCESS) { [weak self] event in
286
+ if DEBUG_THEOPLAYER_EVENTS { PrintUtils.printLog(logText: "[NATIVE] Received CONTENT_PROTECTION_SUCCESS event from THEOplayer") }
287
+ if let forwardedContentProtectionSuccessEvent = self?.onNativeContentProtectionSuccess {
288
+ forwardedContentProtectionSuccessEvent([:])
289
+ }
290
+ }
291
+ if DEBUG_EVENTHANDLER { PrintUtils.printLog(logText: "[NATIVE] ContentProtectionSuccess listener attached to THEOplayer") }
292
+
281
293
  // LOADED_DATA
282
294
  self.loadedDataListener = player.addEventListener(type: PlayerEventTypes.LOADED_DATA) { [weak self] event in
283
295
  if DEBUG_THEOPLAYER_EVENTS { PrintUtils.printLog(logText: "[NATIVE] Received LOADED_DATA event from THEOplayer") }
@@ -451,6 +463,12 @@ public class THEOplayerRCTMainEventHandler {
451
463
  if DEBUG_EVENTHANDLER { PrintUtils.printLog(logText: "[NATIVE] Error listener dettached from THEOplayer") }
452
464
  }
453
465
 
466
+ // CONTENT_PROTECTION_SUCCESS
467
+ if let contentProtectionSuccessListener = self.contentProtectionSuccessListener {
468
+ player.removeEventListener(type: PlayerEventTypes.CONTENT_PROTECTION_SUCCESS, listener: contentProtectionSuccessListener)
469
+ if DEBUG_EVENTHANDLER { PrintUtils.printLog(logText: "[NATIVE] ContentProtectionSuccess listener dettached from THEOplayer") }
470
+ }
471
+
454
472
  // LOADED_DATA
455
473
  if let loadedDataListener = self.loadedDataListener {
456
474
  player.removeEventListener(type: PlayerEventTypes.LOADED_DATA, listener: loadedDataListener)