react-native-theoplayer 11.5.0 → 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.
- package/CHANGELOG.md +12 -1
- package/README.md +1 -0
- package/android/src/main/java/com/theoplayer/PlayerEventEmitter.kt +9 -0
- package/android/src/main/java/com/theoplayer/ReactTHEOplayerContext.kt +58 -85
- package/android/src/main/java/com/theoplayer/ReactTHEOplayerPackage.kt +3 -0
- package/android/src/main/java/com/theoplayer/media/MediaControlModule.kt +102 -0
- package/android/src/main/java/com/theoplayer/media/MediaControlProxy.kt +376 -0
- package/android/src/main/java/com/theoplayer/media/MediaNotificationBuilder.kt +78 -34
- package/android/src/main/java/com/theoplayer/media/MediaPlaybackService.kt +53 -20
- package/android/src/main/java/com/theoplayer/media/MediaSessionConfig.kt +6 -6
- package/android/src/main/java/com/theoplayer/media/MediaSessionConfigAdapter.kt +23 -20
- package/android/src/main/java/com/theoplayer/player/PlayerModule.kt +0 -1
- package/android/src/main/java/com/theoplayer/presentation/PipUtils.kt +98 -93
- package/android/src/main/java/com/theoplayer/util/ReadableExtension.kt +14 -0
- package/android/src/main/res/drawable/ic_next.xml +9 -0
- package/android/src/main/res/drawable/ic_prev.xml +9 -0
- package/android/src/main/res/values/strings.xml +4 -0
- package/ios/THEOplayerRCTBridge.m +16 -0
- package/ios/THEOplayerRCTDebug.swift +3 -0
- package/ios/THEOplayerRCTMainEventHandler.swift +17 -0
- package/ios/THEOplayerRCTTypeUtils.swift +30 -0
- package/ios/THEOplayerRCTView.swift +15 -5
- package/ios/backgroundAudio/THEOplayerRCTBackgroundAudioManager.swift +1 -1
- package/ios/backgroundAudio/THEOplayerRCTNowPlayingManager.swift +49 -3
- package/ios/backgroundAudio/THEOplayerRCTRemoteCommandsManager.swift +151 -68
- package/ios/backgroundAudio/THEOplayerRCTView+MediaControlConfig.swift +25 -11
- package/ios/mediaControl/THEOplayerRCTMediaControlAPI.swift +79 -0
- package/ios/mediaControl/THEOplayerRCTMediaControlManager.swift +38 -0
- package/ios/pip/THEOplayerRCTPipControlsManager.swift +9 -12
- package/lib/commonjs/api/event/PlayerEvent.js +8 -0
- package/lib/commonjs/api/event/PlayerEvent.js.map +1 -1
- package/lib/commonjs/api/media/MediaControlAPI.js +14 -0
- package/lib/commonjs/api/media/MediaControlAPI.js.map +1 -0
- package/lib/commonjs/api/media/barrel.js +11 -0
- package/lib/commonjs/api/media/barrel.js.map +1 -1
- package/lib/commonjs/api/player/PlayerEventMap.js +1 -0
- package/lib/commonjs/api/player/PlayerEventMap.js.map +1 -1
- package/lib/commonjs/api/player/THEOplayer.js.map +1 -1
- package/lib/commonjs/internal/THEOplayerView.js +4 -0
- package/lib/commonjs/internal/THEOplayerView.js.map +1 -1
- package/lib/commonjs/internal/adapter/THEOplayerAdapter.js +6 -0
- package/lib/commonjs/internal/adapter/THEOplayerAdapter.js.map +1 -1
- package/lib/commonjs/internal/adapter/THEOplayerWebAdapter.js +9 -9
- package/lib/commonjs/internal/adapter/THEOplayerWebAdapter.js.map +1 -1
- package/lib/commonjs/internal/adapter/WebEventForwarder.js +5 -0
- package/lib/commonjs/internal/adapter/WebEventForwarder.js.map +1 -1
- package/lib/commonjs/internal/adapter/event/PlayerEvents.js +7 -1
- package/lib/commonjs/internal/adapter/event/PlayerEvents.js.map +1 -1
- package/lib/commonjs/internal/adapter/media/MediaControlNativeAdapter.js +42 -0
- package/lib/commonjs/internal/adapter/media/MediaControlNativeAdapter.js.map +1 -0
- package/lib/commonjs/internal/adapter/media/MediaControlWebAdapter.js +32 -0
- package/lib/commonjs/internal/adapter/media/MediaControlWebAdapter.js.map +1 -0
- package/lib/commonjs/internal/adapter/web/WebMediaSession.js +78 -16
- package/lib/commonjs/internal/adapter/web/WebMediaSession.js.map +1 -1
- package/lib/commonjs/manifest.json +1 -1
- package/lib/module/api/event/PlayerEvent.js +9 -0
- package/lib/module/api/event/PlayerEvent.js.map +1 -1
- package/lib/module/api/media/MediaControlAPI.js +10 -0
- package/lib/module/api/media/MediaControlAPI.js.map +1 -0
- package/lib/module/api/media/barrel.js +1 -0
- package/lib/module/api/media/barrel.js.map +1 -1
- package/lib/module/api/player/PlayerEventMap.js +1 -0
- package/lib/module/api/player/PlayerEventMap.js.map +1 -1
- package/lib/module/api/player/THEOplayer.js.map +1 -1
- package/lib/module/internal/THEOplayerView.js +5 -1
- package/lib/module/internal/THEOplayerView.js.map +1 -1
- package/lib/module/internal/adapter/THEOplayerAdapter.js +6 -0
- package/lib/module/internal/adapter/THEOplayerAdapter.js.map +1 -1
- package/lib/module/internal/adapter/THEOplayerWebAdapter.js +9 -9
- package/lib/module/internal/adapter/THEOplayerWebAdapter.js.map +1 -1
- package/lib/module/internal/adapter/WebEventForwarder.js +6 -1
- package/lib/module/internal/adapter/WebEventForwarder.js.map +1 -1
- package/lib/module/internal/adapter/event/PlayerEvents.js +5 -0
- package/lib/module/internal/adapter/event/PlayerEvents.js.map +1 -1
- package/lib/module/internal/adapter/media/MediaControlNativeAdapter.js +37 -0
- package/lib/module/internal/adapter/media/MediaControlNativeAdapter.js.map +1 -0
- package/lib/module/internal/adapter/media/MediaControlWebAdapter.js +27 -0
- package/lib/module/internal/adapter/media/MediaControlWebAdapter.js.map +1 -0
- package/lib/module/internal/adapter/web/WebMediaSession.js +78 -16
- package/lib/module/internal/adapter/web/WebMediaSession.js.map +1 -1
- package/lib/module/manifest.json +1 -1
- package/lib/typescript/api/event/PlayerEvent.d.ts +9 -0
- package/lib/typescript/api/event/PlayerEvent.d.ts.map +1 -1
- package/lib/typescript/api/media/MediaControlAPI.d.ts +30 -0
- package/lib/typescript/api/media/MediaControlAPI.d.ts.map +1 -0
- package/lib/typescript/api/media/MediaControlConfiguration.d.ts +5 -1
- package/lib/typescript/api/media/MediaControlConfiguration.d.ts.map +1 -1
- package/lib/typescript/api/media/barrel.d.ts +1 -0
- package/lib/typescript/api/media/barrel.d.ts.map +1 -1
- package/lib/typescript/api/player/PlayerEventMap.d.ts +7 -2
- package/lib/typescript/api/player/PlayerEventMap.d.ts.map +1 -1
- package/lib/typescript/api/player/THEOplayer.d.ts +5 -0
- package/lib/typescript/api/player/THEOplayer.d.ts.map +1 -1
- package/lib/typescript/internal/THEOplayerView.d.ts +1 -0
- package/lib/typescript/internal/THEOplayerView.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/THEOplayerAdapter.d.ts +3 -1
- package/lib/typescript/internal/adapter/THEOplayerAdapter.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/THEOplayerWebAdapter.d.ts +3 -2
- package/lib/typescript/internal/adapter/THEOplayerWebAdapter.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/WebEventForwarder.d.ts +1 -0
- package/lib/typescript/internal/adapter/WebEventForwarder.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/event/PlayerEvents.d.ts +4 -1
- package/lib/typescript/internal/adapter/event/PlayerEvents.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/event/native/NativePlayerEvent.d.ts +1 -0
- package/lib/typescript/internal/adapter/event/native/NativePlayerEvent.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/media/MediaControlNativeAdapter.d.ts +12 -0
- package/lib/typescript/internal/adapter/media/MediaControlNativeAdapter.d.ts.map +1 -0
- package/lib/typescript/internal/adapter/media/MediaControlWebAdapter.d.ts +14 -0
- package/lib/typescript/internal/adapter/media/MediaControlWebAdapter.d.ts.map +1 -0
- package/lib/typescript/internal/adapter/web/WebMediaSession.d.ts +10 -3
- package/lib/typescript/internal/adapter/web/WebMediaSession.d.ts.map +1 -1
- package/package.json +3 -3
- package/react-native-theoplayer.podspec +1 -1
- package/src/api/event/PlayerEvent.ts +10 -0
- package/src/api/media/MediaControlAPI.ts +33 -0
- package/src/api/media/MediaControlConfiguration.ts +5 -1
- package/src/api/media/barrel.ts +1 -0
- package/src/api/player/PlayerEventMap.ts +7 -0
- package/src/api/player/THEOplayer.ts +6 -0
- package/src/internal/THEOplayerView.tsx +8 -0
- package/src/internal/adapter/THEOplayerAdapter.ts +9 -0
- package/src/internal/adapter/THEOplayerWebAdapter.ts +12 -9
- package/src/internal/adapter/WebEventForwarder.ts +7 -0
- package/src/internal/adapter/event/PlayerEvents.ts +10 -0
- package/src/internal/adapter/event/native/NativePlayerEvent.ts +2 -0
- package/src/internal/adapter/media/MediaControlNativeAdapter.ts +38 -0
- package/src/internal/adapter/media/MediaControlWebAdapter.ts +28 -0
- package/src/internal/adapter/web/WebMediaSession.ts +85 -21
- package/src/manifest.json +1 -1
- 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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
skipForwardInterval
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
allowLivePlayPause
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
49
|
-
|
|
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
|
-
|
|
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
|
-
|
|
58
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
|
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(
|
|
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
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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>
|
|
@@ -48,6 +48,7 @@ RCT_EXPORT_VIEW_PROPERTY(onNativeDeviceOrientationChanged, RCTDirectEventBlock);
|
|
|
48
48
|
RCT_EXPORT_VIEW_PROPERTY(onNativePlayerReady, RCTDirectEventBlock);
|
|
49
49
|
RCT_EXPORT_VIEW_PROPERTY(onNativePresentationModeChange, RCTDirectEventBlock);
|
|
50
50
|
RCT_EXPORT_VIEW_PROPERTY(onNativeContentProtectionError, RCTDirectEventBlock);
|
|
51
|
+
RCT_EXPORT_VIEW_PROPERTY(onNativeContentProtectionSuccess, RCTDirectEventBlock);
|
|
51
52
|
RCT_EXPORT_VIEW_PROPERTY(onNativeDimensionChange, RCTDirectEventBlock);
|
|
52
53
|
RCT_EXPORT_VIEW_PROPERTY(onNativeVideoResize, RCTDirectEventBlock);
|
|
53
54
|
RCT_EXPORT_VIEW_PROPERTY(onNativeAdEvent, RCTDirectEventBlock);
|
|
@@ -316,3 +317,18 @@ RCT_EXTERN_METHOD(setAdTagParameters:(nonnull NSNumber *)node
|
|
|
316
317
|
|
|
317
318
|
@end
|
|
318
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
|
|
@@ -31,6 +31,7 @@ public class THEOplayerRCTMainEventHandler {
|
|
|
31
31
|
var onNativeWaiting: RCTDirectEventBlock?
|
|
32
32
|
var onNativeCanPlay: RCTDirectEventBlock?
|
|
33
33
|
var onNativeContentProtectionError: RCTDirectEventBlock?
|
|
34
|
+
var onNativeContentProtectionSuccess: RCTDirectEventBlock?
|
|
34
35
|
var onNativeDimensionChange: RCTDirectEventBlock?
|
|
35
36
|
var onNativeVideoResize: RCTDirectEventBlock?
|
|
36
37
|
|
|
@@ -55,6 +56,7 @@ public class THEOplayerRCTMainEventHandler {
|
|
|
55
56
|
private var rateChangeListener: EventListener?
|
|
56
57
|
private var waitingListener: EventListener?
|
|
57
58
|
private var canPlayListener: EventListener?
|
|
59
|
+
private var contentProtectionSuccessListener: EventListener?
|
|
58
60
|
private var videoResizeListener: EventListener?
|
|
59
61
|
|
|
60
62
|
// MARK: player observer
|
|
@@ -279,6 +281,15 @@ public class THEOplayerRCTMainEventHandler {
|
|
|
279
281
|
}
|
|
280
282
|
if DEBUG_EVENTHANDLER { PrintUtils.printLog(logText: "[NATIVE] Error listener attached to THEOplayer") }
|
|
281
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
|
+
|
|
282
293
|
// LOADED_DATA
|
|
283
294
|
self.loadedDataListener = player.addEventListener(type: PlayerEventTypes.LOADED_DATA) { [weak self] event in
|
|
284
295
|
if DEBUG_THEOPLAYER_EVENTS { PrintUtils.printLog(logText: "[NATIVE] Received LOADED_DATA event from THEOplayer") }
|
|
@@ -452,6 +463,12 @@ public class THEOplayerRCTMainEventHandler {
|
|
|
452
463
|
if DEBUG_EVENTHANDLER { PrintUtils.printLog(logText: "[NATIVE] Error listener dettached from THEOplayer") }
|
|
453
464
|
}
|
|
454
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
|
+
|
|
455
472
|
// LOADED_DATA
|
|
456
473
|
if let loadedDataListener = self.loadedDataListener {
|
|
457
474
|
player.removeEventListener(type: PlayerEventTypes.LOADED_DATA, listener: loadedDataListener)
|
|
@@ -114,6 +114,36 @@ class THEOplayerRCTTypeUtils {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
class func mediaControlActionFromString(_ action: String) -> MediaControlAction {
|
|
118
|
+
switch action {
|
|
119
|
+
case "play":
|
|
120
|
+
return MediaControlAction.PLAY
|
|
121
|
+
case "pause":
|
|
122
|
+
return MediaControlAction.PAUSE
|
|
123
|
+
case "skipToPrevious":
|
|
124
|
+
return MediaControlAction.SKIP_TO_PREVIOUS
|
|
125
|
+
case "skipToNext":
|
|
126
|
+
return MediaControlAction.SKIP_TO_NEXT
|
|
127
|
+
default:
|
|
128
|
+
return MediaControlAction.PLAY
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
class func mediaControlActionToString(_ action: MediaControlAction) -> String {
|
|
133
|
+
switch action {
|
|
134
|
+
case MediaControlAction.PLAY:
|
|
135
|
+
return "play"
|
|
136
|
+
case MediaControlAction.PAUSE:
|
|
137
|
+
return "pause"
|
|
138
|
+
case MediaControlAction.SKIP_TO_PREVIOUS:
|
|
139
|
+
return "skipToPrevious"
|
|
140
|
+
case MediaControlAction.SKIP_TO_NEXT:
|
|
141
|
+
return "skipToNext"
|
|
142
|
+
default:
|
|
143
|
+
return "play"
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
117
147
|
class func textTrackEdgeStyleStringFromString(_ style: String) -> String {
|
|
118
148
|
switch style {
|
|
119
149
|
case "dropshadow":
|
|
@@ -42,6 +42,7 @@ public class THEOplayerRCTView: UIView {
|
|
|
42
42
|
var remoteCommandsManager: THEOplayerRCTRemoteCommandsManager
|
|
43
43
|
var pipManager: THEOplayerRCTPipManager
|
|
44
44
|
var pipControlsManager: THEOplayerRCTPipControlsManager
|
|
45
|
+
var mediaControlManager: THEOplayerRCTMediaControlManager
|
|
45
46
|
var isApplicationInBackground: Bool = (UIApplication.shared.applicationState == .background)
|
|
46
47
|
|
|
47
48
|
var adsConfig = AdsConfig()
|
|
@@ -71,12 +72,13 @@ public class THEOplayerRCTView: UIView {
|
|
|
71
72
|
|
|
72
73
|
var mediaControlConfig = MediaControlConfig() {
|
|
73
74
|
didSet {
|
|
74
|
-
self.remoteCommandsManager.
|
|
75
|
+
self.remoteCommandsManager.updateRemoteCommands()
|
|
76
|
+
self.nowPlayingManager.updateNowPlayingInfo()
|
|
75
77
|
}
|
|
76
78
|
}
|
|
77
79
|
var pipConfig = PipConfig() {
|
|
78
80
|
didSet {
|
|
79
|
-
self.pipControlsManager.
|
|
81
|
+
self.pipControlsManager.updatePipControls()
|
|
80
82
|
}
|
|
81
83
|
}
|
|
82
84
|
var backgroundAudioConfig = BackgroundAudioConfig() {
|
|
@@ -115,6 +117,7 @@ public class THEOplayerRCTView: UIView {
|
|
|
115
117
|
self.remoteCommandsManager = THEOplayerRCTRemoteCommandsManager()
|
|
116
118
|
self.pipManager = THEOplayerRCTPipManager()
|
|
117
119
|
self.pipControlsManager = THEOplayerRCTPipControlsManager()
|
|
120
|
+
self.mediaControlManager = THEOplayerRCTMediaControlManager()
|
|
118
121
|
super.init(frame: .zero)
|
|
119
122
|
|
|
120
123
|
self.setupAppStateObservers()
|
|
@@ -151,6 +154,7 @@ public class THEOplayerRCTView: UIView {
|
|
|
151
154
|
self.pipControlsManager.destroy()
|
|
152
155
|
self.presentationModeManager.destroy()
|
|
153
156
|
self.backgroundAudioManager.destroy()
|
|
157
|
+
self.mediaControlManager.destroy()
|
|
154
158
|
|
|
155
159
|
self.destroyBackgroundAudio()
|
|
156
160
|
self.player?.removeAllIntegrations()
|
|
@@ -216,9 +220,9 @@ public class THEOplayerRCTView: UIView {
|
|
|
216
220
|
self.theoliveEventHandler.setPlayer(player)
|
|
217
221
|
self.theoadsEventHandler.setPlayer(player)
|
|
218
222
|
self.castEventHandler.setPlayer(player)
|
|
219
|
-
self.nowPlayingManager.setPlayer(player)
|
|
220
|
-
self.remoteCommandsManager.setPlayer(player)
|
|
221
|
-
self.pipControlsManager.setPlayer(player)
|
|
223
|
+
self.nowPlayingManager.setPlayer(player, view: self)
|
|
224
|
+
self.remoteCommandsManager.setPlayer(player, view: self)
|
|
225
|
+
self.pipControlsManager.setPlayer(player, view: self)
|
|
222
226
|
self.presentationModeManager.setPlayer(player, view: self)
|
|
223
227
|
self.backgroundAudioManager.setPlayer(player, view: self)
|
|
224
228
|
self.pipManager.setView(view: self)
|
|
@@ -476,6 +480,12 @@ public class THEOplayerRCTView: UIView {
|
|
|
476
480
|
if DEBUG_VIEW { PrintUtils.printLog(logText: "[NATIVE] nativeContentProtectionError prop set.") }
|
|
477
481
|
}
|
|
478
482
|
|
|
483
|
+
@objc(setOnNativeContentProtectionSuccess:)
|
|
484
|
+
func setOnNativeContentProtectionSuccess(nativeContentProtectionSuccess: @escaping RCTDirectEventBlock) {
|
|
485
|
+
self.mainEventHandler.onNativeContentProtectionSuccess = nativeContentProtectionSuccess
|
|
486
|
+
if DEBUG_VIEW { PrintUtils.printLog(logText: "[NATIVE] nativeContentProtectionSuccess prop set.") }
|
|
487
|
+
}
|
|
488
|
+
|
|
479
489
|
@objc(setOnNativeDimensionChange:)
|
|
480
490
|
func setOnNativeDimensionChange(nativeDimensionChange: @escaping RCTDirectEventBlock) {
|
|
481
491
|
self.mainEventHandler.onNativeDimensionChange = nativeDimensionChange
|
|
@@ -27,7 +27,7 @@ class THEOplayerRCTBackgroundAudioManager: NSObject, BackgroundPlaybackDelegate
|
|
|
27
27
|
let inPip = view.presentationModeManager.presentationMode == .pictureInPicture
|
|
28
28
|
|
|
29
29
|
if stopOnBackground && !inPip {
|
|
30
|
-
if
|
|
30
|
+
if DEBUG_THEOPLAYER_INTERACTION { PrintUtils.printLog(logText: "[NATIVE] Moved to background, not in pip and stopOnBackground is enabled => stopping playback") }
|
|
31
31
|
player.stop()
|
|
32
32
|
return false
|
|
33
33
|
}
|