@@ -91,22 +91,32 @@ class THEOplayerRCTRemoteCommandsManager: NSObject {
9191 if DEBUG_REMOTECOMMANDS { PrintUtils . printLog ( logText: " [NATIVE] Remote commands initialised. " ) }
9292 }
9393
94+ private func hasActionHandler( for action: MediaControlAction ) -> Bool {
95+ return self . view? . mediaControlManager. hasMediaControlActionHandler ( for: action) ?? false
96+ }
97+
98+ private func executeAction( for action: MediaControlAction ) -> Bool {
99+ return self . view? . mediaControlManager. executeMediaControlAction ( action: action) ?? false
100+ }
101+
94102 func updateRemoteCommands( ) {
95103 let commandCenter = MPRemoteCommandCenter . shared ( )
96104
97- let skipControlsEnabled = self . hasSource && !self . inAd && !self . isLive
98105 let playPauseControlsEnabled = self . hasSource && !self . inAd && ( !self . isLive || self . allowLivePlayPause)
106+ let positionControlEnabled = self . hasSource && !self . inAd && !self . isLive
107+ let seekControlEnabled = self . hasSource && !self . inAd && !self . isLive && !self . hasActionHandler ( for: . SKIP_TO_NEXT) && !self . hasActionHandler ( for: . SKIP_TO_PREVIOUS)
108+ let trackControlEnabled = self . hasSource && !self . inAd && !self . isLive && self . hasActionHandler ( for: . SKIP_TO_NEXT) && self . hasActionHandler ( for: . SKIP_TO_PREVIOUS)
99109
100110 // update the enabled state to have correct visual representation in the lockscreen
101111 commandCenter. pauseCommand. isEnabled = playPauseControlsEnabled
102112 commandCenter. playCommand. isEnabled = playPauseControlsEnabled
103113 commandCenter. togglePlayPauseCommand. isEnabled = playPauseControlsEnabled
104114 commandCenter. stopCommand. isEnabled = playPauseControlsEnabled
105- commandCenter. changePlaybackPositionCommand. isEnabled = skipControlsEnabled
106- commandCenter. skipForwardCommand. isEnabled = skipControlsEnabled
107- commandCenter. skipBackwardCommand. isEnabled = skipControlsEnabled
108- commandCenter. nextTrackCommand. isEnabled = skipControlsEnabled
109- commandCenter. previousTrackCommand. isEnabled = skipControlsEnabled
115+ commandCenter. changePlaybackPositionCommand. isEnabled = positionControlEnabled
116+ commandCenter. skipForwardCommand. isEnabled = seekControlEnabled
117+ commandCenter. skipBackwardCommand. isEnabled = seekControlEnabled
118+ commandCenter. nextTrackCommand. isEnabled = trackControlEnabled
119+ commandCenter. previousTrackCommand. isEnabled = trackControlEnabled
110120
111121 // set configured skip forward/backward intervals
112122 commandCenter. skipForwardCommand. preferredIntervals = [ self . skipForwardInterval]
@@ -122,7 +132,10 @@ class THEOplayerRCTRemoteCommandsManager: NSObject {
122132 if DEBUG_REMOTECOMMANDS { PrintUtils . printLog ( logText: " [NATIVE] Seek to live. " ) }
123133 player. currentTime = . infinity
124134 }
125- player. play ( )
135+ if !self . executeAction ( for: . PLAY) {
136+ if DEBUG_MEDIA_CONTROL_API { PrintUtils . printLog ( logText: " [NATIVE] Executing default Play action. " ) }
137+ player. play ( )
138+ }
126139 if DEBUG_REMOTECOMMANDS { PrintUtils . printLog ( logText: " [NATIVE] Play command handled. " ) }
127140 } else {
128141 if DEBUG_REMOTECOMMANDS { PrintUtils . printLog ( logText: " [NATIVE] Play command not handled. " ) }
@@ -133,7 +146,10 @@ class THEOplayerRCTRemoteCommandsManager: NSObject {
133146 @objc private func onPauseCommand( _ event: MPRemoteCommandEvent ) -> MPRemoteCommandHandlerStatus {
134147 if let player = self . player,
135148 !self . inAd {
136- player. pause ( )
149+ if !self . executeAction ( for: . PAUSE) {
150+ if DEBUG_MEDIA_CONTROL_API { PrintUtils . printLog ( logText: " [NATIVE] Executing default Pause action. " ) }
151+ player. pause ( )
152+ }
137153 if DEBUG_REMOTECOMMANDS { PrintUtils . printLog ( logText: " [NATIVE] Pause command handled. " ) }
138154 } else {
139155 if DEBUG_REMOTECOMMANDS { PrintUtils . printLog ( logText: " [NATIVE] Pause command not handled. " ) }
@@ -144,17 +160,23 @@ class THEOplayerRCTRemoteCommandsManager: NSObject {
144160 @objc private func onTogglePlayPauseCommand( _ event: MPRemoteCommandEvent ) -> MPRemoteCommandHandlerStatus {
145161 if let player = self . player,
146162 !self . inAd {
147- if player. paused {
148- if self . isLive && self . seekToLiveOnResume {
149- if DEBUG_REMOTECOMMANDS { PrintUtils . printLog ( logText: " [NATIVE] Seek to live. " ) }
150- player. currentTime = . infinity
163+ if player. paused {
164+ if !self . executeAction ( for: . PLAY) {
165+ if DEBUG_MEDIA_CONTROL_API { PrintUtils . printLog ( logText: " [NATIVE] Executing default Toogle play action. " ) }
166+ if self . isLive && self . seekToLiveOnResume {
167+ if DEBUG_REMOTECOMMANDS { PrintUtils . printLog ( logText: " [NATIVE] Seek to live. " ) }
168+ player. currentTime = . infinity
169+ }
170+ player. play ( )
171+ }
172+ if DEBUG_REMOTECOMMANDS { PrintUtils . printLog ( logText: " [NATIVE] Toggled to playing. " ) }
173+ } else {
174+ if !self . executeAction ( for: . PAUSE) {
175+ if DEBUG_MEDIA_CONTROL_API { PrintUtils . printLog ( logText: " [NATIVE] Executing default Toogle pause action. " ) }
176+ player. pause ( )
177+ }
178+ if DEBUG_REMOTECOMMANDS { PrintUtils . printLog ( logText: " [NATIVE] Toggled to paused. " ) }
151179 }
152- if DEBUG_REMOTECOMMANDS { PrintUtils . printLog ( logText: " [NATIVE] Toggled to playing. " ) }
153- player. play ( )
154- } else {
155- if DEBUG_REMOTECOMMANDS { PrintUtils . printLog ( logText: " [NATIVE] Toggled to paused. " ) }
156- player. pause ( )
157- }
158180 if DEBUG_REMOTECOMMANDS { PrintUtils . printLog ( logText: " [NATIVE] Toggle play/pause command handled. " ) }
159181 } else {
160182 if DEBUG_REMOTECOMMANDS { PrintUtils . printLog ( logText: " [NATIVE] Toggle play/pause command not handled. " ) }
@@ -166,7 +188,10 @@ class THEOplayerRCTRemoteCommandsManager: NSObject {
166188 if let player = self . player,
167189 !self . inAd {
168190 if !player. paused {
169- player. pause ( )
191+ if !self . executeAction ( for: . PAUSE) {
192+ if DEBUG_MEDIA_CONTROL_API { PrintUtils . printLog ( logText: " [NATIVE] Executing default Pause action. " ) }
193+ player. pause ( )
194+ }
170195 }
171196 if DEBUG_REMOTECOMMANDS { PrintUtils . printLog ( logText: " [NATIVE] Stop command handled. " ) }
172197 } else {
@@ -213,10 +238,14 @@ class THEOplayerRCTRemoteCommandsManager: NSObject {
213238
214239 @objc private func onPreviousTrackCommand( _ event: MPRemoteCommandEvent ) -> MPRemoteCommandHandlerStatus {
215240 if let player = self . player,
216- self . convertSkipToSeek,
217241 !self . isLive,
218242 !self . inAd {
219- player. currentTime = player. currentTime - Double( truncating: self . skipBackwardInterval)
243+ if !self . executeAction ( for: . SKIP_TO_PREVIOUS) {
244+ if DEBUG_MEDIA_CONTROL_API { PrintUtils . printLog ( logText: " [NATIVE] Executing default Skip to previous action. " ) }
245+ if self . convertSkipToSeek {
246+ player. currentTime = player. currentTime - Double( truncating: self . skipBackwardInterval)
247+ }
248+ }
220249 if DEBUG_REMOTECOMMANDS { PrintUtils . printLog ( logText: " [NATIVE] previous track command handled as skip backward command. " ) }
221250 } else {
222251 if DEBUG_REMOTECOMMANDS { PrintUtils . printLog ( logText: " [NATIVE] previous track command not handled. " ) }
@@ -226,10 +255,14 @@ class THEOplayerRCTRemoteCommandsManager: NSObject {
226255
227256 @objc private func onNextTrackCommand( _ event: MPRemoteCommandEvent ) -> MPRemoteCommandHandlerStatus {
228257 if let player = self . player,
229- self . convertSkipToSeek,
230258 !self . isLive,
231259 !self . inAd {
232- player. currentTime = player. currentTime + Double( truncating: self . skipForwardInterval)
260+ if !self . executeAction ( for: . SKIP_TO_NEXT) {
261+ if DEBUG_MEDIA_CONTROL_API { PrintUtils . printLog ( logText: " [NATIVE] Executing default Skip to next action. " ) }
262+ if self . convertSkipToSeek {
263+ player. currentTime = player. currentTime + Double( truncating: self . skipForwardInterval)
264+ }
265+ }
233266 if DEBUG_REMOTECOMMANDS { PrintUtils . printLog ( logText: " [NATIVE] next track command handled as skip forward command. " ) }
234267 } else {
235268 if DEBUG_REMOTECOMMANDS { PrintUtils . printLog ( logText: " [NATIVE] next track command not handled. " ) }
0 commit comments