From c77d186ceb99f10a3f5f738c7737fa1a51031672 Mon Sep 17 00:00:00 2001 From: Yu Sung Date: Wed, 18 Dec 2024 20:23:15 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9E=A0=EA=B8=88=ED=99=94=EB=A9=B4=20?= =?UTF-8?q?=ED=94=8C=EB=A0=88=EC=9D=B4=EC=96=B4=20=EC=9E=AC=EC=83=9D?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=20=EB=8F=99=EA=B8=B0=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Player/ContentPlayerPlayManager.swift | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/SodaLive/Sources/Content/Player/ContentPlayerPlayManager.swift b/SodaLive/Sources/Content/Player/ContentPlayerPlayManager.swift index 5f54e26..34641b1 100644 --- a/SodaLive/Sources/Content/Player/ContentPlayerPlayManager.swift +++ b/SodaLive/Sources/Content/Player/ContentPlayerPlayManager.swift @@ -70,6 +70,7 @@ final class ContentPlayerPlayManager: NSObject, ObservableObject { .sink { [weak self] currentTime in if !(self?.isEditing ?? false) { self?.currentTime = CMTimeGetSeconds(currentTime) + MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyElapsedPlaybackTime] = self?.currentTime } } .store(in: &cancellables) @@ -114,8 +115,8 @@ final class ContentPlayerPlayManager: NSObject, ObservableObject { try audioSession.setCategory(.playback, mode: .moviePlayback) try audioSession.setActive(true) - self.registerRemoteControlEvents() self.fetchAlbumArtAndUpdateNowPlayingInfo() + self.registerRemoteControlEvents() } catch { DEBUG_LOG("Audio Session 설정 실패: \(error.localizedDescription)") } @@ -180,7 +181,7 @@ final class ContentPlayerPlayManager: NSObject, ObservableObject { } func playOrPause() { - if player?.timeControlStatus == .paused { + if player?.timeControlStatus == .paused && !isPlaying { player?.play() isPlaying = true } else { @@ -276,7 +277,7 @@ final class ContentPlayerPlayManager: NSObject, ObservableObject { switch result { case .success(let value): self?.registerNowPlayingInfoCenter(with: value.image) - case .failure(let error): + case .failure(_): self?.registerNowPlayingInfoCenter(with: nil) } } @@ -284,7 +285,7 @@ final class ContentPlayerPlayManager: NSObject, ObservableObject { private func registerNowPlayingInfoCenter(with albumArtImage: UIImage?) { let center = MPNowPlayingInfoCenter.default() - var nowPlayingInfo = center.nowPlayingInfo ?? [String: Any]() + var nowPlayingInfo = [String: Any]() nowPlayingInfo[MPMediaItemPropertyTitle] = title nowPlayingInfo[MPMediaItemPropertyArtist] = nickname @@ -294,11 +295,8 @@ final class ContentPlayerPlayManager: NSObject, ObservableObject { nowPlayingInfo[MPMediaItemPropertyArtwork] = artwork } - nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = duration - nowPlayingInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = currentTime - if let player = player { - // 콘텐츠 재생 시간에 따른 progressBar 초기화 + nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = player.currentItem?.duration.seconds nowPlayingInfo[MPNowPlayingInfoPropertyPlaybackRate] = player.rate } @@ -319,9 +317,6 @@ final class ContentPlayerPlayManager: NSObject, ObservableObject { self.playOrPause() return .success } - - center.seekForwardCommand.isEnabled = false - center.seekBackwardCommand.isEnabled = false } private func unRegisterRemoteControlEvents() {