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.
- package/CHANGELOG.md +26 -1
- package/README.md +1 -0
- package/android/src/main/java/com/theoplayer/PlayerEventEmitter.kt +21 -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/RCTBridgeModule+ViewHelpers.swift +59 -0
- package/ios/THEOplayerRCTBridge.m +17 -0
- package/ios/THEOplayerRCTDebug.swift +3 -0
- package/ios/THEOplayerRCTMainEventHandler.swift +18 -0
- package/ios/THEOplayerRCTPlayerAPI.swift +194 -254
- package/ios/THEOplayerRCTTypeUtils.swift +30 -0
- package/ios/THEOplayerRCTView.swift +22 -6
- package/ios/ads/THEOplayerRCTAdsAPI+DAI.swift +22 -21
- package/ios/ads/THEOplayerRCTAdsAPI+Omid.swift +4 -9
- package/ios/ads/THEOplayerRCTAdsAPI.swift +39 -50
- package/ios/backgroundAudio/THEOplayerRCTBackgroundAudioManager.swift +2 -2
- package/ios/backgroundAudio/THEOplayerRCTNowPlayingManager.swift +144 -47
- package/ios/backgroundAudio/THEOplayerRCTRemoteCommandsManager.swift +151 -68
- package/ios/backgroundAudio/THEOplayerRCTView+MediaControlConfig.swift +25 -11
- package/ios/casting/THEOplayerRCTCastAPI+Airplay.swift +20 -22
- package/ios/casting/THEOplayerRCTCastAPI+Chromecast.swift +28 -34
- package/ios/casting/THEOplayerRCTCastAPI.swift +5 -8
- package/ios/eventBroadcasting/THEOplayerRCTEventBroadcastAPI.swift +2 -4
- package/ios/mediaControl/THEOplayerRCTMediaControlAPI.swift +79 -0
- package/ios/mediaControl/THEOplayerRCTMediaControlManager.swift +38 -0
- package/ios/pip/THEOplayerRCTPipControlsManager.swift +9 -12
- package/ios/theoAds/THEOplayerRCTTHEOAdsAPI.swift +16 -18
- package/ios/theolive/THEOplayerRCTTHEOliveAPI.swift +14 -14
- package/lib/commonjs/api/error/ContentProtectionError.js +2 -0
- package/lib/commonjs/api/error/ContentProtectionError.js.map +1 -0
- package/lib/commonjs/api/error/barrel.js +11 -0
- package/lib/commonjs/api/error/barrel.js.map +1 -1
- package/lib/commonjs/api/event/PlayerEvent.js +16 -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 +2 -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 +8 -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 +27 -0
- package/lib/commonjs/internal/adapter/WebEventForwarder.js.map +1 -1
- package/lib/commonjs/internal/adapter/event/PlayerEvents.js +14 -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/error/ContentProtectionError.js +2 -0
- package/lib/module/api/error/ContentProtectionError.js.map +1 -0
- package/lib/module/api/error/barrel.js +1 -0
- package/lib/module/api/error/barrel.js.map +1 -1
- package/lib/module/api/event/PlayerEvent.js +18 -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 +2 -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 +9 -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 +28 -1
- package/lib/module/internal/adapter/WebEventForwarder.js.map +1 -1
- package/lib/module/internal/adapter/event/PlayerEvents.js +11 -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/error/ContentProtectionError.d.ts +53 -0
- package/lib/typescript/api/error/ContentProtectionError.d.ts.map +1 -0
- package/lib/typescript/api/error/barrel.d.ts +1 -0
- package/lib/typescript/api/error/barrel.d.ts.map +1 -1
- package/lib/typescript/api/event/PlayerEvent.d.ts +24 -1
- 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 +12 -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 +2 -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 +2 -0
- package/lib/typescript/internal/adapter/WebEventForwarder.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/event/PlayerEvents.d.ts +8 -1
- package/lib/typescript/internal/adapter/event/PlayerEvents.d.ts.map +1 -1
- package/lib/typescript/internal/adapter/event/native/NativePlayerEvent.d.ts +5 -1
- 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/error/ContentProtectionError.ts +58 -0
- package/src/api/error/barrel.ts +1 -0
- package/src/api/event/PlayerEvent.ts +26 -1
- 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 +14 -0
- package/src/api/player/THEOplayer.ts +6 -0
- package/src/internal/THEOplayerView.tsx +16 -0
- package/src/internal/adapter/THEOplayerAdapter.ts +9 -0
- package/src/internal/adapter/THEOplayerWebAdapter.ts +12 -9
- package/src/internal/adapter/WebEventForwarder.ts +26 -0
- package/src/internal/adapter/event/PlayerEvents.ts +18 -0
- package/src/internal/adapter/event/native/NativePlayerEvent.ts +7 -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
package/CHANGELOG.md
CHANGED
|
@@ -5,8 +5,33 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/)
|
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [11.6.0]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Added the `MediaControl` API for controlling the media session and lock screen controls with custom handlers.
|
|
13
|
+
- Added support for the `contentprotectionsuccess` event on all platforms
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- Upgraded example app to support React Native v0.86.2.
|
|
18
|
+
|
|
19
|
+
## [11.5.0]
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- Fixed an issue on iOS where fetching the artwork for the `NowPlayingInfo` could cause a crash due to unsafe thread usage.
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- Added `contentprotectionerror` player event on Web and Android platforms.
|
|
28
|
+
|
|
8
29
|
## [11.4.1] - 26-07-22
|
|
9
30
|
|
|
31
|
+
### Changed
|
|
32
|
+
|
|
33
|
+
- Added RCTBridgeModule extension on iOS, with helper methods to resolve the view and native player APIs.
|
|
34
|
+
|
|
10
35
|
### Fixed
|
|
11
36
|
|
|
12
37
|
- Fixed an issue on iOS where sideloaded texttracks were not stored for cached playout.
|
|
@@ -668,7 +693,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
|
668
693
|
|
|
669
694
|
### Changed
|
|
670
695
|
|
|
671
|
-
-
|
|
696
|
+
- Upgraded example app to support React Native v0.75.
|
|
672
697
|
|
|
673
698
|
## [8.5.0] - 24-10-21
|
|
674
699
|
|
package/README.md
CHANGED
|
@@ -186,6 +186,7 @@ This section gives an overview of features, limitations and known issues:
|
|
|
186
186
|
- [Digital Rights Management (DRM)](./doc/drm.md)
|
|
187
187
|
- [Expo](./doc/expo.md)
|
|
188
188
|
- [Fullscreen presentation](./doc/fullscreen.md)
|
|
189
|
+
- [Media Control](./doc/mediacontrol.md)
|
|
189
190
|
- [Media Caching](./doc/media-caching.md)
|
|
190
191
|
- [Migrating to THEOplayer 9.x](./doc/migrating-to-react-native-theoplayer-9.md)
|
|
191
192
|
- [Migrating to THEOplayer 10.x🔥](./doc/migrating-to-react-native-theoplayer-10.md)
|
|
@@ -85,6 +85,8 @@ private const val EVENT_THEOLIVE_EVENT = "onNativeTHEOliveEvent"
|
|
|
85
85
|
private const val EVENT_THEOADS_EVENT = "onNativeTHEOadsEvent"
|
|
86
86
|
private const val EVENT_PRESENTATIONMODECHANGE = "onNativePresentationModeChange"
|
|
87
87
|
private const val EVENT_VOLUMECHANGE = "onNativeVolumeChange"
|
|
88
|
+
private const val EVENT_CONTENTPROTECTIONERROR = "onNativeContentProtectionError"
|
|
89
|
+
private const val EVENT_CONTENTPROTECTIONSUCCESS = "onNativeContentProtectionSuccess"
|
|
88
90
|
private const val EVENT_DIMENSIONCHANGE = "onNativeDimensionChange"
|
|
89
91
|
private const val EVENT_VIDEORESIZE = "onNativeVideoResize"
|
|
90
92
|
|
|
@@ -132,6 +134,8 @@ class PlayerEventEmitter internal constructor(
|
|
|
132
134
|
EVENT_THEOADS_EVENT,
|
|
133
135
|
EVENT_PRESENTATIONMODECHANGE,
|
|
134
136
|
EVENT_VOLUMECHANGE,
|
|
137
|
+
EVENT_CONTENTPROTECTIONERROR,
|
|
138
|
+
EVENT_CONTENTPROTECTIONSUCCESS,
|
|
135
139
|
EVENT_DIMENSIONCHANGE,
|
|
136
140
|
EVENT_VIDEORESIZE
|
|
137
141
|
)
|
|
@@ -171,6 +175,8 @@ class PlayerEventEmitter internal constructor(
|
|
|
171
175
|
EVENT_THEOADS_EVENT,
|
|
172
176
|
EVENT_PRESENTATIONMODECHANGE,
|
|
173
177
|
EVENT_VOLUMECHANGE,
|
|
178
|
+
EVENT_CONTENTPROTECTIONERROR,
|
|
179
|
+
EVENT_CONTENTPROTECTIONSUCCESS,
|
|
174
180
|
EVENT_DIMENSIONCHANGE,
|
|
175
181
|
EVENT_VIDEORESIZE
|
|
176
182
|
)
|
|
@@ -246,6 +252,10 @@ class PlayerEventEmitter internal constructor(
|
|
|
246
252
|
EventListener { event: PresentationModeChange -> onPresentationModeChange(event) }
|
|
247
253
|
playerListeners[PlayerEventTypes.VOLUMECHANGE] =
|
|
248
254
|
EventListener { event: VolumeChangeEvent -> onVolumeChange(event) }
|
|
255
|
+
playerListeners[PlayerEventTypes.CONTENTPROTECTIONERROR] =
|
|
256
|
+
EventListener { event: ContentProtectionErrorEvent -> onContentProtectionError(event) }
|
|
257
|
+
playerListeners[PlayerEventTypes.CONTENTPROTECTIONSUCCESS] =
|
|
258
|
+
EventListener<PlayerEvent<*>> { onContentProtectionSuccess() }
|
|
249
259
|
playerListeners[PlayerEventTypes.RESIZE] =
|
|
250
260
|
EventListener { event: ResizeEvent -> onResize(event) }
|
|
251
261
|
textTrackListeners[TextTrackListEventTypes.ADDTRACK] =
|
|
@@ -479,6 +489,17 @@ class PlayerEventEmitter internal constructor(
|
|
|
479
489
|
)
|
|
480
490
|
}
|
|
481
491
|
|
|
492
|
+
private fun onContentProtectionError(event: ContentProtectionErrorEvent) {
|
|
493
|
+
receiveEvent(
|
|
494
|
+
EVENT_CONTENTPROTECTIONERROR,
|
|
495
|
+
PayloadBuilder().error(event.errorObject.code.id.toString(), event.errorObject.message).build()
|
|
496
|
+
)
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
private fun onContentProtectionSuccess() {
|
|
500
|
+
receiveEvent(EVENT_CONTENTPROTECTIONSUCCESS, null)
|
|
501
|
+
}
|
|
502
|
+
|
|
482
503
|
private fun onResize(event: ResizeEvent) {
|
|
483
504
|
receiveEvent(
|
|
484
505
|
EVENT_VIDEORESIZE,
|
|
@@ -34,32 +34,16 @@ import com.theoplayer.android.api.millicast.MillicastIntegrationFactory
|
|
|
34
34
|
import com.theoplayer.android.api.player.Player
|
|
35
35
|
import com.theoplayer.android.api.player.RenderingTarget
|
|
36
36
|
import com.theoplayer.android.connector.mediasession.MediaSessionConnector
|
|
37
|
-
import com.theoplayer.android.connector.mediasession.MediaSessionListener
|
|
38
37
|
import com.theoplayer.audio.AudioBecomingNoisyManager
|
|
39
38
|
import com.theoplayer.audio.AudioFocusManager
|
|
40
39
|
import com.theoplayer.audio.BackgroundAudioConfig
|
|
40
|
+
import com.theoplayer.media.MediaControlProxy
|
|
41
41
|
import com.theoplayer.media.MediaPlaybackService
|
|
42
|
-
import com.theoplayer.media.MediaQueueNavigator
|
|
43
42
|
import com.theoplayer.media.MediaSessionConfig
|
|
44
43
|
import java.util.concurrent.atomic.AtomicBoolean
|
|
45
44
|
|
|
46
45
|
private const val TAG = "ReactTHEOplayerContext"
|
|
47
46
|
|
|
48
|
-
private const val ALLOWED_PLAYBACK_ACTIONS = (
|
|
49
|
-
PlaybackStateCompat.ACTION_PLAY_PAUSE or
|
|
50
|
-
PlaybackStateCompat.ACTION_PLAY or
|
|
51
|
-
PlaybackStateCompat.ACTION_PAUSE or
|
|
52
|
-
PlaybackStateCompat.ACTION_SEEK_TO or
|
|
53
|
-
PlaybackStateCompat.ACTION_FAST_FORWARD or
|
|
54
|
-
PlaybackStateCompat.ACTION_REWIND or
|
|
55
|
-
PlaybackStateCompat.ACTION_SET_PLAYBACK_SPEED)
|
|
56
|
-
|
|
57
|
-
private const val ALLOWED_PLAY_PAUSE_ACTIONS = (
|
|
58
|
-
PlaybackStateCompat.ACTION_PLAY_PAUSE or
|
|
59
|
-
PlaybackStateCompat.ACTION_PLAY or
|
|
60
|
-
PlaybackStateCompat.ACTION_PAUSE)
|
|
61
|
-
|
|
62
|
-
@Suppress("SimplifyBooleanWithConstants", "KotlinConstantConditions")
|
|
63
47
|
class ReactTHEOplayerContext private constructor(
|
|
64
48
|
private val reactContext: ThemedReactContext,
|
|
65
49
|
private val configAdapter: PlayerConfigAdapter
|
|
@@ -67,7 +51,7 @@ class ReactTHEOplayerContext private constructor(
|
|
|
67
51
|
private val mainHandler = Handler(Looper.getMainLooper())
|
|
68
52
|
private var isBound = AtomicBoolean()
|
|
69
53
|
private var binder: MediaPlaybackService.MediaPlaybackBinder? = null
|
|
70
|
-
|
|
54
|
+
|
|
71
55
|
private var audioBecomingNoisyManager = AudioBecomingNoisyManager(reactContext) {
|
|
72
56
|
// Audio is about to become 'noisy' due to a change in audio outputs: pause the player
|
|
73
57
|
player.pause()
|
|
@@ -80,11 +64,41 @@ class ReactTHEOplayerContext private constructor(
|
|
|
80
64
|
field = value
|
|
81
65
|
}
|
|
82
66
|
|
|
83
|
-
var
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
67
|
+
private var mediaSessionConnector: MediaSessionConnector? = null
|
|
68
|
+
|
|
69
|
+
private var mediaSessionConfig: MediaSessionConfig = configAdapter.mediaSessionConfig()
|
|
70
|
+
var mediaControlProxy: MediaControlProxy = MediaControlProxy()
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Whether this player context currently owns the (potentially shared) media session.
|
|
74
|
+
*
|
|
75
|
+
* When multiple players run with background audio, they share a single [MediaPlaybackService]
|
|
76
|
+
* and its media session; only the player that most recently took ownership drives the lock-screen
|
|
77
|
+
* widget. Without a background service each player owns its own local session, so it always owns it.
|
|
78
|
+
*/
|
|
79
|
+
private fun ownsMediaSession(): Boolean {
|
|
80
|
+
return binder?.isActivePlayerContext(this) ?: true
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Enable or disable the media session for this player instance at runtime.
|
|
85
|
+
*
|
|
86
|
+
* When enabling, this player takes over the (potentially shared) media session: it becomes the
|
|
87
|
+
* active source for Now Playing metadata, remote commands and the foreground notification.
|
|
88
|
+
* When disabling, the shared session is only torn down if this player still owns it, so a
|
|
89
|
+
* newly-activated player is never clobbered regardless of the order in which enable/disable run.
|
|
90
|
+
*/
|
|
91
|
+
fun setMediaSessionEnabled(enabled: Boolean) {
|
|
92
|
+
mediaSessionConfig = mediaSessionConfig.copy(mediaSessionEnabled = enabled)
|
|
93
|
+
if (enabled) {
|
|
94
|
+
// Take over the (shared) foreground service/notification for this player.
|
|
95
|
+
binder?.setPlayerContext(this)
|
|
96
|
+
} else if (!ownsMediaSession()) {
|
|
97
|
+
// Only tear down when we still own the session; otherwise another player already took over.
|
|
98
|
+
return
|
|
87
99
|
}
|
|
100
|
+
applyMediaSessionConfig(mediaSessionConnector, mediaSessionConfig)
|
|
101
|
+
}
|
|
88
102
|
|
|
89
103
|
lateinit var playerView: THEOplayerView
|
|
90
104
|
|
|
@@ -130,9 +144,6 @@ class ReactTHEOplayerContext private constructor(
|
|
|
130
144
|
|
|
131
145
|
// Pass player context
|
|
132
146
|
binder?.setPlayerContext(this@ReactTHEOplayerContext)
|
|
133
|
-
|
|
134
|
-
// Apply background audio config
|
|
135
|
-
binder?.setEnablePlaybackControls(mediaSessionConfig)
|
|
136
147
|
}
|
|
137
148
|
|
|
138
149
|
override fun onServiceDisconnected(className: ComponentName?) {
|
|
@@ -140,19 +151,6 @@ class ReactTHEOplayerContext private constructor(
|
|
|
140
151
|
}
|
|
141
152
|
}
|
|
142
153
|
|
|
143
|
-
private val mediaSessionListener = object : MediaSessionListener() {
|
|
144
|
-
override fun onStop() {
|
|
145
|
-
binder?.stopForegroundService()
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
override fun onPlay() {
|
|
149
|
-
// Optionally seek to live, if configured.
|
|
150
|
-
if (mediaSessionConfig.seekToLiveOnResume && player.duration.isInfinite()) {
|
|
151
|
-
player.currentTime = Double.POSITIVE_INFINITY
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
154
|
private fun applyBackgroundPlaybackConfig(
|
|
157
155
|
config: BackgroundAudioConfig,
|
|
158
156
|
prevConfig: BackgroundAudioConfig?
|
|
@@ -184,21 +182,6 @@ class ReactTHEOplayerContext private constructor(
|
|
|
184
182
|
}
|
|
185
183
|
}
|
|
186
184
|
|
|
187
|
-
private fun applyAllowedMediaControls() {
|
|
188
|
-
// Reduce allowed set of remote control playback actions for ads & live streams.
|
|
189
|
-
val isLive = player.duration.isInfinite()
|
|
190
|
-
val isInAd = player.ads.isPlaying
|
|
191
|
-
mediaSessionConnector?.enabledPlaybackActions = when {
|
|
192
|
-
// Allow trick-play for live events if configured
|
|
193
|
-
isLive && mediaSessionConfig.allowLivePlayPause -> ALLOWED_PLAY_PAUSE_ACTIONS
|
|
194
|
-
isLive && !mediaSessionConfig.allowLivePlayPause -> 0
|
|
195
|
-
// Do not allow playback actions during ad play-out
|
|
196
|
-
isInAd -> 0
|
|
197
|
-
|
|
198
|
-
else -> ALLOWED_PLAYBACK_ACTIONS
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
185
|
private fun bindMediaPlaybackService() {
|
|
203
186
|
// Bind to an existing service, if available
|
|
204
187
|
// A bound service runs only as long as another application component is bound to it.
|
|
@@ -265,6 +248,9 @@ class ReactTHEOplayerContext private constructor(
|
|
|
265
248
|
addIntegrations()
|
|
266
249
|
addListeners()
|
|
267
250
|
|
|
251
|
+
// Let the proxy track which media control actions are available for this player.
|
|
252
|
+
mediaControlProxy.setPlayer(player)
|
|
253
|
+
|
|
268
254
|
audioFocusManager = AudioFocusManager(reactContext, player)
|
|
269
255
|
|
|
270
256
|
if (!BuildConfig.USE_PLAYBACK_SERVICE || !isBackgroundAudioEnabled) {
|
|
@@ -279,15 +265,8 @@ class ReactTHEOplayerContext private constructor(
|
|
|
279
265
|
// Destroy any existent media session
|
|
280
266
|
mediaSessionConnector?.destroy()
|
|
281
267
|
|
|
282
|
-
// Create and initialize the media session
|
|
283
|
-
val mediaSession = MediaSessionCompat(reactContext, TAG)
|
|
284
|
-
|
|
285
|
-
// Do not let MediaButtons restart the player when media session is not active.
|
|
286
|
-
// https://developer.android.com/media/legacy/media-buttons#restarting-inactive-mediasessions
|
|
287
|
-
mediaSession.setMediaButtonReceiver(null)
|
|
288
|
-
|
|
289
268
|
// Create a MediaSessionConnector and attach the THEOplayer instance.
|
|
290
|
-
mediaSessionConnector = MediaSessionConnector(
|
|
269
|
+
mediaSessionConnector = MediaSessionConnector(MediaSessionCompat(reactContext, TAG)).also {
|
|
291
270
|
applyMediaSessionConfig(it, mediaSessionConfig)
|
|
292
271
|
}
|
|
293
272
|
}
|
|
@@ -296,9 +275,15 @@ class ReactTHEOplayerContext private constructor(
|
|
|
296
275
|
connector: MediaSessionConnector?,
|
|
297
276
|
config: MediaSessionConfig
|
|
298
277
|
) {
|
|
299
|
-
connector
|
|
278
|
+
if (connector == null) {
|
|
279
|
+
// Keep the proxy up to date even while there is no media session to attach to, as its config
|
|
280
|
+
// also drives the PiP controls.
|
|
281
|
+
mediaControlProxy.setConfig(config)
|
|
282
|
+
return
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
connector.apply {
|
|
300
286
|
debug = BuildConfig.LOG_MEDIASESSION_EVENTS
|
|
301
|
-
removeListener(mediaSessionListener)
|
|
302
287
|
|
|
303
288
|
player = this@ReactTHEOplayerContext.player
|
|
304
289
|
|
|
@@ -306,21 +291,16 @@ class ReactTHEOplayerContext private constructor(
|
|
|
306
291
|
// is backgrounded.
|
|
307
292
|
setActive(!isHostPaused && BuildConfig.EXTENSION_MEDIASESSION && config.mediaSessionEnabled)
|
|
308
293
|
|
|
309
|
-
skipForwardInterval = config.skipForwardInterval
|
|
310
|
-
skipBackwardsInterval = config.skipBackwardInterval
|
|
311
|
-
|
|
312
294
|
// Pass metadata from source description
|
|
313
295
|
setMediaSessionMetadata(player?.source)
|
|
314
296
|
|
|
315
297
|
// Do not let MediaButtons restart the player when media session is not active.
|
|
316
298
|
// https://developer.android.com/media/legacy/media-buttons#restarting-inactive-mediasessions
|
|
317
|
-
|
|
299
|
+
mediaSession.setMediaButtonReceiver(null)
|
|
318
300
|
|
|
319
|
-
//
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
addListener(mediaSessionListener)
|
|
301
|
+
// Route all media control actions through the MediaControlProxy, which will decide whether to
|
|
302
|
+
// invoke the action or not.
|
|
303
|
+
mediaControlProxy.attach(this, binder, config)
|
|
324
304
|
}
|
|
325
305
|
}
|
|
326
306
|
|
|
@@ -390,12 +370,6 @@ class ReactTHEOplayerContext private constructor(
|
|
|
390
370
|
private val onSourceChange = EventListener<SourceChangeEvent> {
|
|
391
371
|
mediaSessionConnector?.setMediaSessionMetadata(player.source)
|
|
392
372
|
binder?.updateNotification()
|
|
393
|
-
applyAllowedMediaControls()
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
private val onLoadedMetadata = EventListener<LoadedMetadataEvent> {
|
|
397
|
-
binder?.updateNotification()
|
|
398
|
-
applyAllowedMediaControls()
|
|
399
373
|
}
|
|
400
374
|
|
|
401
375
|
private val onPlay = EventListener<PlayEvent> {
|
|
@@ -403,14 +377,12 @@ class ReactTHEOplayerContext private constructor(
|
|
|
403
377
|
bindMediaPlaybackService()
|
|
404
378
|
}
|
|
405
379
|
binder?.updateNotification(PlaybackStateCompat.STATE_PLAYING)
|
|
406
|
-
applyAllowedMediaControls()
|
|
407
380
|
audioBecomingNoisyManager.setEnabled(true)
|
|
408
381
|
audioFocusManager?.requestAudioFocus()
|
|
409
382
|
}
|
|
410
383
|
|
|
411
384
|
private val onPause = EventListener<PauseEvent> {
|
|
412
385
|
binder?.updateNotification(PlaybackStateCompat.STATE_PAUSED)
|
|
413
|
-
applyAllowedMediaControls()
|
|
414
386
|
audioBecomingNoisyManager.setEnabled(false)
|
|
415
387
|
}
|
|
416
388
|
|
|
@@ -436,7 +408,6 @@ class ReactTHEOplayerContext private constructor(
|
|
|
436
408
|
private fun addListeners() {
|
|
437
409
|
player.apply {
|
|
438
410
|
addEventListener(PlayerEventTypes.SOURCECHANGE, onSourceChange)
|
|
439
|
-
addEventListener(PlayerEventTypes.LOADEDMETADATA, onLoadedMetadata)
|
|
440
411
|
addEventListener(PlayerEventTypes.PAUSE, onPause)
|
|
441
412
|
addEventListener(PlayerEventTypes.PLAY, onPlay)
|
|
442
413
|
addEventListener(PlayerEventTypes.ENDED, onEnded)
|
|
@@ -450,7 +421,6 @@ class ReactTHEOplayerContext private constructor(
|
|
|
450
421
|
private fun removeListeners() {
|
|
451
422
|
player.apply {
|
|
452
423
|
removeEventListener(PlayerEventTypes.SOURCECHANGE, onSourceChange)
|
|
453
|
-
removeEventListener(PlayerEventTypes.LOADEDMETADATA, onLoadedMetadata)
|
|
454
424
|
removeEventListener(PlayerEventTypes.PAUSE, onPause)
|
|
455
425
|
removeEventListener(PlayerEventTypes.PLAY, onPlay)
|
|
456
426
|
removeEventListener(PlayerEventTypes.ENDED, onEnded)
|
|
@@ -492,7 +462,9 @@ class ReactTHEOplayerContext private constructor(
|
|
|
492
462
|
*/
|
|
493
463
|
fun onHostResume() {
|
|
494
464
|
isHostPaused = false
|
|
495
|
-
mediaSessionConnector?.setActive(
|
|
465
|
+
mediaSessionConnector?.setActive(
|
|
466
|
+
BuildConfig.EXTENSION_MEDIASESSION && mediaSessionConfig.mediaSessionEnabled
|
|
467
|
+
)
|
|
496
468
|
playerView.onResume()
|
|
497
469
|
if (!player.isPaused) {
|
|
498
470
|
audioFocusManager?.requestAudioFocus()
|
|
@@ -500,9 +472,9 @@ class ReactTHEOplayerContext private constructor(
|
|
|
500
472
|
}
|
|
501
473
|
|
|
502
474
|
fun destroy() {
|
|
503
|
-
|
|
504
|
-
removeListeners()
|
|
475
|
+
removeListeners()
|
|
505
476
|
|
|
477
|
+
if (BuildConfig.USE_PLAYBACK_SERVICE) {
|
|
506
478
|
// Remove service from foreground
|
|
507
479
|
binder?.stopForegroundService()
|
|
508
480
|
|
|
@@ -510,6 +482,7 @@ class ReactTHEOplayerContext private constructor(
|
|
|
510
482
|
unbindMediaPlaybackService()
|
|
511
483
|
}
|
|
512
484
|
audioFocusManager?.abandonAudioFocus()
|
|
485
|
+
mediaControlProxy.destroy()
|
|
513
486
|
mediaSessionConnector?.destroy()
|
|
514
487
|
playerView.onDestroy()
|
|
515
488
|
}
|
|
@@ -10,6 +10,7 @@ import com.theoplayer.cache.CacheModule
|
|
|
10
10
|
import com.theoplayer.drm.ContentProtectionModule
|
|
11
11
|
import com.theoplayer.cast.CastModule
|
|
12
12
|
import com.theoplayer.broadcast.EventBroadcastModule
|
|
13
|
+
import com.theoplayer.media.MediaControlModule
|
|
13
14
|
import com.theoplayer.player.PlayerModule
|
|
14
15
|
import com.theoplayer.theolive.THEOliveModule
|
|
15
16
|
import com.theoplayer.theoads.THEOadsModule
|
|
@@ -26,6 +27,7 @@ class ReactTHEOplayerPackage : BaseReactPackage() {
|
|
|
26
27
|
EventBroadcastModule.NAME -> EventBroadcastModule(reactContext)
|
|
27
28
|
THEOliveModule.NAME -> THEOliveModule(reactContext)
|
|
28
29
|
THEOadsModule.NAME -> THEOadsModule(reactContext)
|
|
30
|
+
MediaControlModule.NAME -> MediaControlModule(reactContext)
|
|
29
31
|
else -> null
|
|
30
32
|
}
|
|
31
33
|
}
|
|
@@ -45,6 +47,7 @@ class ReactTHEOplayerPackage : BaseReactPackage() {
|
|
|
45
47
|
EventBroadcastModule.NAME to EventBroadcastModule.INFO,
|
|
46
48
|
THEOliveModule.NAME to THEOliveModule.INFO,
|
|
47
49
|
THEOadsModule.NAME to THEOadsModule.INFO,
|
|
50
|
+
MediaControlModule.NAME to MediaControlModule.INFO,
|
|
48
51
|
)
|
|
49
52
|
}
|
|
50
53
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
package com.theoplayer.media
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
5
|
+
import com.facebook.react.bridge.ReactMethod
|
|
6
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
8
|
+
import com.facebook.react.bridge.Arguments
|
|
9
|
+
import com.facebook.react.bridge.WritableMap
|
|
10
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
11
|
+
import com.theoplayer.ReactTHEOplayerView
|
|
12
|
+
import com.theoplayer.util.ViewResolver
|
|
13
|
+
|
|
14
|
+
private const val PROP_TAG = "tag"
|
|
15
|
+
private const val PROP_ACTION = "action"
|
|
16
|
+
|
|
17
|
+
enum class MediaControlAction(val propName: String) {
|
|
18
|
+
PLAY("play"),
|
|
19
|
+
PAUSE("pause"),
|
|
20
|
+
SKIP_TO_NEXT("skipToNext"),
|
|
21
|
+
SKIP_TO_PREVIOUS("skipToPrevious");
|
|
22
|
+
|
|
23
|
+
companion object {
|
|
24
|
+
private val map = entries.associateBy(MediaControlAction::propName)
|
|
25
|
+
fun fromPropName(propName: String): MediaControlAction? = map[propName]
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@Suppress("unused")
|
|
30
|
+
@ReactModule(name = MediaControlModule.NAME)
|
|
31
|
+
class MediaControlModule(context: ReactApplicationContext) : ReactContextBaseJavaModule(context) {
|
|
32
|
+
companion object {
|
|
33
|
+
const val NAME = "THEORCTMediaControlModule"
|
|
34
|
+
val INFO = ReactModuleInfo(
|
|
35
|
+
name = NAME,
|
|
36
|
+
className = NAME,
|
|
37
|
+
canOverrideExistingModule = false,
|
|
38
|
+
needsEagerInit = false,
|
|
39
|
+
isCxxModule = false,
|
|
40
|
+
isTurboModule = false,
|
|
41
|
+
)
|
|
42
|
+
const val MEDIA_CONTROL_EVENT = "MediaControlEvent"
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private val viewResolver: ViewResolver = ViewResolver(context)
|
|
46
|
+
|
|
47
|
+
override fun getName(): String {
|
|
48
|
+
return NAME
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
override fun getConstants(): Map<String, Any> {
|
|
52
|
+
return mapOf("MEDIA_CONTROL_EVENT" to MEDIA_CONTROL_EVENT)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Register a handler for a media control action. Instead of storing the Callback, use event emitter for multiple notifications.
|
|
57
|
+
* When the action occurs, call sendEvent to notify JS listeners.
|
|
58
|
+
*/
|
|
59
|
+
@ReactMethod
|
|
60
|
+
fun setHandler(tag: Int, action: String) {
|
|
61
|
+
val mediaControlAction = MediaControlAction.fromPropName(action)
|
|
62
|
+
if (mediaControlAction != null) {
|
|
63
|
+
viewResolver.resolveViewByTag(tag) { view: ReactTHEOplayerView? ->
|
|
64
|
+
view?.playerContext?.mediaControlProxy?.setHandler(mediaControlAction, {
|
|
65
|
+
sendEvent(MEDIA_CONTROL_EVENT, Arguments.createMap().apply {
|
|
66
|
+
putInt(PROP_TAG, tag)
|
|
67
|
+
putString(PROP_ACTION, action)
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Remove a previously registered handler for a media control action, restoring the default behaviour.
|
|
76
|
+
*/
|
|
77
|
+
@ReactMethod
|
|
78
|
+
fun removeHandler(tag: Int, action: String) {
|
|
79
|
+
val mediaControlAction = MediaControlAction.fromPropName(action)
|
|
80
|
+
if (mediaControlAction != null) {
|
|
81
|
+
viewResolver.resolveViewByTag(tag) { view: ReactTHEOplayerView? ->
|
|
82
|
+
view?.playerContext?.mediaControlProxy?.removeHandler(mediaControlAction)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Enable or disable the media session for the player instance at runtime.
|
|
89
|
+
*/
|
|
90
|
+
@ReactMethod
|
|
91
|
+
fun setEnabled(tag: Int, enabled: Boolean) {
|
|
92
|
+
viewResolver.resolveViewByTag(tag) { view: ReactTHEOplayerView? ->
|
|
93
|
+
view?.playerContext?.setMediaSessionEnabled(enabled)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private fun sendEvent(eventName: String, params: WritableMap?) {
|
|
98
|
+
reactApplicationContext
|
|
99
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
100
|
+
.emit(eventName, params)
|
|
101
|
+
}
|
|
102
|
+
}
|