잠금화면 플레이어
- 이미지 다운로드 Kingfisher로 변경 - 시간 표시 player에서 불러오지 않고 플레이어 화면에 표시하는 프로퍼티로 시간을 표시하도록 수정
This commit is contained in:
		| @@ -55,7 +55,6 @@ struct ContentDetailPlayView: View { | ||||
|                 } else if audioContent.releaseDate == nil && !isAlertPreview || (audioContent.isActivePreview && !audioContent.contentUrl.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty) { | ||||
|                     Image(isPlaying() ? "btn_audio_content_pause" : isAlertPreview ? "btn_audio_content_preview_play" : "btn_audio_content_play") | ||||
|                         .onTapGesture { | ||||
|                             ContentPlayManager.shared.stopAudio() | ||||
|                             ContentPlayerPlayManager.shared.resetPlayer() | ||||
|                              | ||||
|                             if isPlaying() { | ||||
|   | ||||
| @@ -10,6 +10,8 @@ import AVKit | ||||
| import MediaPlayer | ||||
| import Combine | ||||
|  | ||||
| import Kingfisher | ||||
|  | ||||
| final class ContentPlayerPlayManager: NSObject, ObservableObject { | ||||
|     static let shared = ContentPlayerPlayManager() | ||||
|      | ||||
| @@ -261,29 +263,23 @@ final class ContentPlayerPlayManager: NSObject, ObservableObject { | ||||
|             return | ||||
|         } | ||||
|          | ||||
|         // URLSession을 사용하여 비동기적으로 이미지 다운로드 | ||||
|         URLSession.shared.dataTask(with: url) { [weak self] data, _, error in | ||||
|             if let error = error { | ||||
|                 print("앨범 아트 다운로드 실패: \(error.localizedDescription)") | ||||
|                 DispatchQueue.main.async { | ||||
|                     self?.registerNowPlayingInfoCenter(with: nil) // 앨범 아트 없이 업데이트 | ||||
|                 } | ||||
|                 return | ||||
|         let processor = DownsamplingImageProcessor(size: CGSize(width: 240, height: 240)) | ||||
|          | ||||
|         KingfisherManager.shared.retrieveImage( | ||||
|             with: url, | ||||
|             options: [ | ||||
|                 .processor(processor), | ||||
|                 .scaleFactor(UIScreen.main.scale), | ||||
|                 .cacheOriginalImage | ||||
|             ] | ||||
|         ) { [weak self] result in | ||||
|             switch result { | ||||
|             case .success(let value): | ||||
|                 self?.registerNowPlayingInfoCenter(with: value.image) | ||||
|             case .failure(let error): | ||||
|                 self?.registerNowPlayingInfoCenter(with: nil) | ||||
|             } | ||||
|              | ||||
|             guard let data = data, let image = UIImage(data: data) else { | ||||
|                 print("이미지 데이터를 가져오지 못했습니다.") | ||||
|                 DispatchQueue.main.async { | ||||
|                     self?.registerNowPlayingInfoCenter(with: nil) // 앨범 아트 없이 업데이트 | ||||
|                 } | ||||
|                 return | ||||
|             } | ||||
|              | ||||
|             // 성공적으로 다운로드된 이미지를 사용 | ||||
|             DispatchQueue.main.async { | ||||
|                 self?.registerNowPlayingInfoCenter(with: image) | ||||
|             } | ||||
|         }.resume() | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     private func registerNowPlayingInfoCenter(with albumArtImage: UIImage?) { | ||||
| @@ -298,13 +294,12 @@ final class ContentPlayerPlayManager: NSObject, ObservableObject { | ||||
|             nowPlayingInfo[MPMediaItemPropertyArtwork] = artwork | ||||
|         } | ||||
|          | ||||
|         nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = duration | ||||
|         nowPlayingInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = currentTime | ||||
|          | ||||
|         if let player = player { | ||||
|             // 콘텐츠 총 길이 | ||||
|             nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = player.currentItem?.asset.duration.seconds ?? .zero | ||||
|             // 콘텐츠 재생 시간에 따른 progressBar 초기화 | ||||
|             nowPlayingInfo[MPNowPlayingInfoPropertyPlaybackRate] = player.rate | ||||
|             // 콘텐츠 현재 재생시간 | ||||
|             nowPlayingInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = player.currentTime().seconds | ||||
|         } | ||||
|          | ||||
|         center.nowPlayingInfo = nowPlayingInfo | ||||
| @@ -325,25 +320,14 @@ final class ContentPlayerPlayManager: NSObject, ObservableObject { | ||||
|             return .success | ||||
|         } | ||||
|          | ||||
|         center.seekForwardCommand.isEnabled = true | ||||
|         center.seekForwardCommand.addTarget { [unowned self] (commandEvent) -> MPRemoteCommandHandlerStatus in | ||||
|             self.playNextContent() | ||||
|             return .success | ||||
|         } | ||||
|          | ||||
|         center.seekBackwardCommand.isEnabled = true | ||||
|         center.seekBackwardCommand.addTarget { [unowned self] (commandEvent) -> MPRemoteCommandHandlerStatus in | ||||
|             self.playPreviousContent() | ||||
|             return .success | ||||
|         } | ||||
|         center.seekForwardCommand.isEnabled = false | ||||
|         center.seekBackwardCommand.isEnabled = false | ||||
|     } | ||||
|      | ||||
|     private func unRegisterRemoteControlEvents() { | ||||
|         let center = MPRemoteCommandCenter.shared() | ||||
|         center.playCommand.removeTarget(nil) | ||||
|         center.pauseCommand.removeTarget(nil) | ||||
|         center.skipForwardCommand.removeTarget(nil) | ||||
|         center.skipBackwardCommand.removeTarget(nil) | ||||
|         UIApplication.shared.endReceivingRemoteControlEvents() | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Yu Sung
					Yu Sung