Skip to content

Commit

Permalink
Merge pull request #361 from THEOplayer/bugfix/disable-commands-on-un…
Browse files Browse the repository at this point in the history
…defined-source

Bugfix/disable commands on undefined source
  • Loading branch information
wvanhaevre authored Aug 8, 2024
2 parents 8210c25 + 0684018 commit ceb1ca1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
## Unreleased

### Fixed

- Fixed an issue where the Lockscreen showed enabled controls when the player has no valid source.

### Added

Expand Down
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 ceb1ca1

Please sign in to comment.