잠금화면 플레이어 재생시간 동기화
This commit is contained in:
parent
6c12152f81
commit
c77d186ceb
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue