잠금화면 플레이어 재생시간 동기화
This commit is contained in:
parent
6c12152f81
commit
c77d186ceb
|
@ -70,6 +70,7 @@ final class ContentPlayerPlayManager: NSObject, ObservableObject {
|
||||||
.sink { [weak self] currentTime in
|
.sink { [weak self] currentTime in
|
||||||
if !(self?.isEditing ?? false) {
|
if !(self?.isEditing ?? false) {
|
||||||
self?.currentTime = CMTimeGetSeconds(currentTime)
|
self?.currentTime = CMTimeGetSeconds(currentTime)
|
||||||
|
MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyElapsedPlaybackTime] = self?.currentTime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
|
@ -114,8 +115,8 @@ final class ContentPlayerPlayManager: NSObject, ObservableObject {
|
||||||
try audioSession.setCategory(.playback, mode: .moviePlayback)
|
try audioSession.setCategory(.playback, mode: .moviePlayback)
|
||||||
try audioSession.setActive(true)
|
try audioSession.setActive(true)
|
||||||
|
|
||||||
self.registerRemoteControlEvents()
|
|
||||||
self.fetchAlbumArtAndUpdateNowPlayingInfo()
|
self.fetchAlbumArtAndUpdateNowPlayingInfo()
|
||||||
|
self.registerRemoteControlEvents()
|
||||||
} catch {
|
} catch {
|
||||||
DEBUG_LOG("Audio Session 설정 실패: \(error.localizedDescription)")
|
DEBUG_LOG("Audio Session 설정 실패: \(error.localizedDescription)")
|
||||||
}
|
}
|
||||||
|
@ -180,7 +181,7 @@ final class ContentPlayerPlayManager: NSObject, ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
func playOrPause() {
|
func playOrPause() {
|
||||||
if player?.timeControlStatus == .paused {
|
if player?.timeControlStatus == .paused && !isPlaying {
|
||||||
player?.play()
|
player?.play()
|
||||||
isPlaying = true
|
isPlaying = true
|
||||||
} else {
|
} else {
|
||||||
|
@ -276,7 +277,7 @@ final class ContentPlayerPlayManager: NSObject, ObservableObject {
|
||||||
switch result {
|
switch result {
|
||||||
case .success(let value):
|
case .success(let value):
|
||||||
self?.registerNowPlayingInfoCenter(with: value.image)
|
self?.registerNowPlayingInfoCenter(with: value.image)
|
||||||
case .failure(let error):
|
case .failure(_):
|
||||||
self?.registerNowPlayingInfoCenter(with: nil)
|
self?.registerNowPlayingInfoCenter(with: nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -284,7 +285,7 @@ final class ContentPlayerPlayManager: NSObject, ObservableObject {
|
||||||
|
|
||||||
private func registerNowPlayingInfoCenter(with albumArtImage: UIImage?) {
|
private func registerNowPlayingInfoCenter(with albumArtImage: UIImage?) {
|
||||||
let center = MPNowPlayingInfoCenter.default()
|
let center = MPNowPlayingInfoCenter.default()
|
||||||
var nowPlayingInfo = center.nowPlayingInfo ?? [String: Any]()
|
var nowPlayingInfo = [String: Any]()
|
||||||
|
|
||||||
nowPlayingInfo[MPMediaItemPropertyTitle] = title
|
nowPlayingInfo[MPMediaItemPropertyTitle] = title
|
||||||
nowPlayingInfo[MPMediaItemPropertyArtist] = nickname
|
nowPlayingInfo[MPMediaItemPropertyArtist] = nickname
|
||||||
|
@ -294,11 +295,8 @@ final class ContentPlayerPlayManager: NSObject, ObservableObject {
|
||||||
nowPlayingInfo[MPMediaItemPropertyArtwork] = artwork
|
nowPlayingInfo[MPMediaItemPropertyArtwork] = artwork
|
||||||
}
|
}
|
||||||
|
|
||||||
nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = duration
|
|
||||||
nowPlayingInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = currentTime
|
|
||||||
|
|
||||||
if let player = player {
|
if let player = player {
|
||||||
// 콘텐츠 재생 시간에 따른 progressBar 초기화
|
nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = player.currentItem?.duration.seconds
|
||||||
nowPlayingInfo[MPNowPlayingInfoPropertyPlaybackRate] = player.rate
|
nowPlayingInfo[MPNowPlayingInfoPropertyPlaybackRate] = player.rate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,9 +317,6 @@ final class ContentPlayerPlayManager: NSObject, ObservableObject {
|
||||||
self.playOrPause()
|
self.playOrPause()
|
||||||
return .success
|
return .success
|
||||||
}
|
}
|
||||||
|
|
||||||
center.seekForwardCommand.isEnabled = false
|
|
||||||
center.seekBackwardCommand.isEnabled = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func unRegisterRemoteControlEvents() {
|
private func unRegisterRemoteControlEvents() {
|
||||||
|
|
Loading…
Reference in New Issue