Skip to content

Commit

Permalink
Only enable commands when the player has a valid source.
Browse files Browse the repository at this point in the history
  • Loading branch information
wvanhaevre committed Aug 7, 2024
1 parent 8210c25 commit bf2e7f6
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions ios/backgroundAudio/THEOplayerRCTRemoteCommandsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class THEOplayerRCTRemoteCommandsManager: NSObject {
private weak var player: THEOplayer?
private var isLive: Bool = false
private var inAd: Bool = false
private var hasSource: Bool = false
private var mediaControlConfig = MediaControlConfig()

// MARK: player Listeners
Expand Down Expand Up @@ -40,6 +41,7 @@ class THEOplayerRCTRemoteCommandsManager: NSObject {
private func initRemoteCommands() {
self.isLive = false
self.inAd = false
self.hasSource = false
let commandCenter = MPRemoteCommandCenter.shared()

commandCenter.playCommand.isEnabled = false
Expand Down Expand Up @@ -80,13 +82,14 @@ class THEOplayerRCTRemoteCommandsManager: NSObject {
let commandCenter = MPRemoteCommandCenter.shared()

// update the enabled state to have correct visual representation in the lockscreen
commandCenter.playCommand.isEnabled = !self.inAd
commandCenter.pauseCommand.isEnabled = !self.inAd
commandCenter.togglePlayPauseCommand.isEnabled = !self.inAd
commandCenter.stopCommand.isEnabled = !self.inAd
commandCenter.changePlaybackPositionCommand.isEnabled = !self.isLive && !self.inAd
commandCenter.skipForwardCommand.isEnabled = !self.isLive && !self.inAd
commandCenter.skipBackwardCommand.isEnabled = !self.isLive && !self.inAd
commandCenter.pauseCommand.isEnabled = self.hasSource && !self.inAd
commandCenter.playCommand.isEnabled = self.hasSource && !self.inAd
commandCenter.pauseCommand.isEnabled = self.hasSource && !self.inAd
commandCenter.togglePlayPauseCommand.isEnabled = self.hasSource && !self.inAd
commandCenter.stopCommand.isEnabled = self.hasSource && !self.inAd
commandCenter.changePlaybackPositionCommand.isEnabled = self.hasSource && !self.isLive && !self.inAd
commandCenter.skipForwardCommand.isEnabled = self.hasSource && !self.isLive && !self.inAd
commandCenter.skipBackwardCommand.isEnabled = self.hasSource && !self.isLive && !self.inAd
commandCenter.nextTrackCommand.isEnabled = !self.isLive && !self.inAd
commandCenter.previousTrackCommand.isEnabled = !self.isLive && !self.inAd

Expand Down Expand Up @@ -228,6 +231,7 @@ class THEOplayerRCTRemoteCommandsManager: NSObject {
self.sourceChangeListener = player.addEventListener(type: PlayerEventTypes.SOURCE_CHANGE) { [weak self] event in
self?.isLive = false
self?.inAd = false
self?.hasSource = (event.source != nil)
self?.updateRemoteCommands()
}

Expand Down

0 comments on commit bf2e7f6

Please sign in to comment.