From 6adc87797a8ee05be35ab5a0bb634e979beba46b Mon Sep 17 00:00:00 2001 From: Alfonso Grillo Date: Thu, 13 Oct 2022 12:48:58 +0200 Subject: [PATCH 1/3] Remove audio player info --- .../VoiceMessages/VoiceMessageMediaServiceProvider.swift | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Riot/Modules/Room/VoiceMessages/VoiceMessageMediaServiceProvider.swift b/Riot/Modules/Room/VoiceMessages/VoiceMessageMediaServiceProvider.swift index 3037c67d07..ffba217b0f 100644 --- a/Riot/Modules/Room/VoiceMessages/VoiceMessageMediaServiceProvider.swift +++ b/Riot/Modules/Room/VoiceMessages/VoiceMessageMediaServiceProvider.swift @@ -252,14 +252,8 @@ import MediaPlayer return } - let artwork = MPMediaItemArtwork(boundsSize: Constants.roomAvatarImageSize) { [weak self] size in - return self?.roomAvatar ?? UIImage() - } - let nowPlayingInfoCenter = MPNowPlayingInfoCenter.default() - nowPlayingInfoCenter.nowPlayingInfo = [MPMediaItemPropertyTitle: audioPlayer.displayName ?? VectorL10n.voiceMessageLockScreenPlaceholder, - MPMediaItemPropertyArtist: currentRoomSummary?.displayname as Any, - MPMediaItemPropertyArtwork: artwork, + nowPlayingInfoCenter.nowPlayingInfo = [MPMediaItemPropertyTitle: VectorL10n.voiceMessageLockScreenPlaceholder, MPMediaItemPropertyPlaybackDuration: audioPlayer.duration as Any, MPNowPlayingInfoPropertyElapsedPlaybackTime: audioPlayer.currentTime as Any] } From 7fe2d3e20231818e677781df4a795ba52e018621 Mon Sep 17 00:00:00 2001 From: Alfonso Grillo Date: Thu, 13 Oct 2022 12:53:37 +0200 Subject: [PATCH 2/3] Add allowBackgroundAudioMessagePlayback build setting --- Config/BuildSettings.swift | 2 ++ .../Room/VoiceMessages/VoiceMessageAudioPlayer.swift | 11 +++++++++++ .../VoiceMessageMediaServiceProvider.swift | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/Config/BuildSettings.swift b/Config/BuildSettings.swift index 375e522288..f346202023 100644 --- a/Config/BuildSettings.swift +++ b/Config/BuildSettings.swift @@ -234,6 +234,8 @@ final class BuildSettings: NSObject { static let allowInviteExernalUsers: Bool = true + static let allowBackgroundAudioMessagePlayback: Bool = true + // MARK: - Side Menu static let enableSideMenu: Bool = true && !newAppLayoutEnabled static let sideMenuShowInviteFriends: Bool = true diff --git a/Riot/Modules/Room/VoiceMessages/VoiceMessageAudioPlayer.swift b/Riot/Modules/Room/VoiceMessages/VoiceMessageAudioPlayer.swift index ebe038c6d1..be3847ceca 100644 --- a/Riot/Modules/Room/VoiceMessages/VoiceMessageAudioPlayer.swift +++ b/Riot/Modules/Room/VoiceMessages/VoiceMessageAudioPlayer.swift @@ -41,6 +41,7 @@ class VoiceMessageAudioPlayer: NSObject { private var playbackBufferEmptyObserver: NSKeyValueObservation? private var rateObserver: NSKeyValueObservation? private var playToEndObserver: NSObjectProtocol? + private var appBackgroundObserver: NSObjectProtocol? private let delegateContainer = DelegateContainer() @@ -198,6 +199,15 @@ class VoiceMessageAudioPlayer: NSObject { (delegate as? VoiceMessageAudioPlayerDelegate)?.audioPlayerDidFinishPlaying(self) } } + + appBackgroundObserver = NotificationCenter.default.addObserver(forName: UIApplication.didEnterBackgroundNotification, object: nil, queue: nil) { [weak self] _ in + guard let self = self, !BuildSettings.allowBackgroundAudioMessagePlayback else { return } + + self.pause() + self.delegateContainer.notifyDelegatesWithBlock { delegate in + (delegate as? VoiceMessageAudioPlayerDelegate)?.audioPlayerDidPausePlaying(self) + } + } } private func removeObservers() { @@ -205,6 +215,7 @@ class VoiceMessageAudioPlayer: NSObject { playbackBufferEmptyObserver?.invalidate() rateObserver?.invalidate() NotificationCenter.default.removeObserver(playToEndObserver as Any) + NotificationCenter.default.removeObserver(appBackgroundObserver as Any) } } diff --git a/Riot/Modules/Room/VoiceMessages/VoiceMessageMediaServiceProvider.swift b/Riot/Modules/Room/VoiceMessages/VoiceMessageMediaServiceProvider.swift index ffba217b0f..54262f8289 100644 --- a/Riot/Modules/Room/VoiceMessages/VoiceMessageMediaServiceProvider.swift +++ b/Riot/Modules/Room/VoiceMessages/VoiceMessageMediaServiceProvider.swift @@ -183,6 +183,10 @@ import MediaPlayer } private func setUpRemoteCommandCenter() { + guard BuildSettings.allowBackgroundAudioMessagePlayback else { + return + } + displayLink.isPaused = false UIApplication.shared.beginReceivingRemoteControlEvents() From ac655c482551f017b148c3bd378bf758b9ae4b94 Mon Sep 17 00:00:00 2001 From: Alfonso Grillo Date: Thu, 13 Oct 2022 14:51:21 +0200 Subject: [PATCH 3/3] Add changelog.d file --- changelog.d/pr-6870.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/pr-6870.feature diff --git a/changelog.d/pr-6870.feature b/changelog.d/pr-6870.feature new file mode 100644 index 0000000000..2a4ba4edc0 --- /dev/null +++ b/changelog.d/pr-6870.feature @@ -0,0 +1 @@ +Changed the info in the background audio message player.