-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: 재생화면 버그 수정 #215
bug: 재생화면 버그 수정 #215
Changes from 8 commits
7d4b824
7136ba5
9ec4202
c19dd02
aee14c8
6dff710
b1cbfb0
b5b8c2b
6a41923
963074e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ protocol PlaybackDisplayLogic: AnyObject { | |
func showPlayerSlider(viewModel: PlaybackModels.DisplayPlaybackVideo.ViewModel) | ||
func teleportPlaybackCell(viewModel: PlaybackModels.DisplayPlaybackVideo.ViewModel) | ||
func leavePlaybackView(viewModel: PlaybackModels.DisplayPlaybackVideo.ViewModel) | ||
func routeToBack(viewModel: PlaybackModels.DisplayPlaybackVideo.ViewModel) | ||
func configureDataSource(viewModel: PlaybackModels.ConfigurePlaybackCell.ViewModel) | ||
func seekVideo(viewModel: PlaybackModels.SeekVideo.ViewModel) | ||
} | ||
|
@@ -42,7 +43,6 @@ final class PlaybackViewController: BaseViewController { | |
}() | ||
|
||
// MARK: - Properties | ||
private var playerSlider: LOSlider = LOSlider() | ||
|
||
private var dataSource: UICollectionViewDiffableDataSource<Section, Models.PlaybackVideo>? | ||
|
||
|
@@ -91,6 +91,9 @@ final class PlaybackViewController: BaseViewController { | |
override func viewWillDisappear(_ animated: Bool) { | ||
super.viewWillDisappear(animated) | ||
interactor?.leavePlaybackView() | ||
if isMovingFromParent { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isMovingFromParent .. 뷰컨에 이런 프로퍼티가 있군요..? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 근데 얘 역할이 몬가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. viewWillDisappear되는 경우가 두가지가 있습니다. 하나는 backbutton눌러서 이동할 때고 다른 하나는 Tabbar로 이동하는 경우입니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이해했습니다 !! 새로운 걸 알아가요.. |
||
interactor?.moveToBack() | ||
} | ||
} | ||
|
||
override func viewDidLayoutSubviews() { | ||
|
@@ -114,49 +117,16 @@ final class PlaybackViewController: BaseViewController { | |
|
||
override func setUI() { | ||
super.setUI() | ||
addWindowPlayerSlider() | ||
} | ||
|
||
private func addWindowPlayerSlider() { | ||
let scenes = UIApplication.shared.connectedScenes | ||
let windowScene = scenes.first as? UIWindowScene | ||
let window = windowScene?.windows.first | ||
guard let playerSliderWidth: CGFloat = windowScene?.screen.bounds.width else { return } | ||
guard let windowHeight: CGFloat = windowScene?.screen.bounds.height else { return } | ||
guard let tabBarHeight: CGFloat = self.tabBarController?.tabBar.frame.height else { return } | ||
playerSlider.frame = CGRect(x: 0, y: (windowHeight - tabBarHeight - LOSlider.loSliderHeight / 2), width: playerSliderWidth, height: LOSlider.loSliderHeight) | ||
window?.addSubview(playerSlider) | ||
playerSlider.window?.windowLevel = UIWindow.Level.normal + 1 | ||
} | ||
|
||
private func setPlayerSlider(at playbackView: PlaybackView) { | ||
let interval: CMTime = CMTimeMakeWithSeconds(1, preferredTimescale: Int32(NSEC_PER_SEC)) | ||
playbackView.playerView.player?.addPeriodicTimeObserver(forInterval: interval, queue: .main, using: { [weak self] currentTime in | ||
self?.updateSlider(currentTime: currentTime, playerView: playbackView.playerView) | ||
}) | ||
playerSlider.addTarget(self, action: #selector(didChangedSliderValue(_:)), for: .valueChanged) | ||
} | ||
|
||
private func updateSlider(currentTime: CMTime, playerView: PlayerView) { | ||
guard let currentItem: AVPlayerItem = playerView.player?.currentItem else { return } | ||
let duration: CMTime = currentItem.duration | ||
if CMTIME_IS_INVALID(duration) { return } | ||
playerSlider.value = Float(CMTimeGetSeconds(currentTime) / CMTimeGetSeconds(duration)) | ||
} | ||
|
||
private func slowShowPlayerSlider() async { | ||
do { | ||
try await Task.sleep(nanoseconds: 1_000_000_00) | ||
playerSlider.isHidden = false | ||
} catch { | ||
os_log("Fail Waiting show Player Slider") | ||
} | ||
} | ||
|
||
@objc private func didChangedSliderValue(_ sender: LOSlider) { | ||
let request: Models.SeekVideo.Request = Models.SeekVideo.Request(currentLocation: Float64(sender.value)) | ||
interactor?.controlPlaybackMovie(with: request) | ||
} | ||
|
||
private func moveToBackViewController() { | ||
interactor?.moveToBack() | ||
} | ||
} | ||
|
||
extension PlaybackViewController: PlaybackDisplayLogic { | ||
|
@@ -172,20 +142,16 @@ extension PlaybackViewController: PlaybackDisplayLogic { | |
} | ||
|
||
func stopPrevPlayerAndPlayCurPlayer(viewModel: PlaybackModels.DisplayPlaybackVideo.ViewModel) { | ||
guard let tabBarHeight: CGFloat = self.tabBarController?.tabBar.frame.height else { return } | ||
if let prevCell = viewModel.prevCell { | ||
prevCell.playbackView.removePlayerSlider() | ||
prevCell.playbackView.stopPlayer() | ||
prevCell.playbackView.replayPlayer() | ||
} | ||
if let curCell = viewModel.curCell { | ||
curCell.addPlayerSlider(tabBarHeight: tabBarHeight) | ||
curCell.playbackView.addTargetPlayerSlider() | ||
curCell.playbackView.playPlayer() | ||
setPlayerSlider(at: curCell.playbackView) | ||
// Slider가 원점으로 돌아가는 시간 필요 | ||
// DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) { | ||
// self.playerSlider.isHidden = false | ||
// } | ||
Task { | ||
await slowShowPlayerSlider() | ||
} | ||
} | ||
} | ||
|
||
|
@@ -198,7 +164,7 @@ extension PlaybackViewController: PlaybackDisplayLogic { | |
} | ||
|
||
func showPlayerSlider(viewModel: PlaybackModels.DisplayPlaybackVideo.ViewModel) { | ||
playerSlider.isHidden = false | ||
viewModel.curCell?.playbackView.playerSlider?.isHidden = false | ||
} | ||
|
||
func moveInitialPlaybackCell(viewModel: PlaybackModels.SetInitialPlaybackCell.ViewModel) { | ||
|
@@ -213,7 +179,6 @@ extension PlaybackViewController: PlaybackDisplayLogic { | |
} | ||
|
||
func leavePlaybackView(viewModel: PlaybackModels.DisplayPlaybackVideo.ViewModel) { | ||
playerSlider.isHidden = true | ||
viewModel.prevCell?.playbackView.stopPlayer() | ||
} | ||
|
||
|
@@ -228,7 +193,6 @@ extension PlaybackViewController: PlaybackDisplayLogic { | |
} | ||
} | ||
cell.addAVPlayer(url: playbackVideo.playbackInfo.videoURL) | ||
self.setPlayerSlider(at: cell.playbackView) | ||
return cell | ||
} | ||
} | ||
|
@@ -238,6 +202,14 @@ extension PlaybackViewController: PlaybackDisplayLogic { | |
viewModel.curCell.playbackView.seekPlayer(seekTime: seekTime) | ||
viewModel.curCell.playbackView.playPlayer() | ||
} | ||
|
||
func routeToBack(viewModel: PlaybackModels.DisplayPlaybackVideo.ViewModel) { | ||
var curCell = viewModel.curCell | ||
curCell?.resetObserver() | ||
curCell?.playbackView.resetPlayer() | ||
curCell = nil | ||
} | ||
|
||
} | ||
|
||
extension PlaybackViewController: UICollectionViewDelegateFlowLayout { | ||
|
@@ -269,7 +241,7 @@ extension PlaybackViewController: UICollectionViewDelegate { | |
} | ||
|
||
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) { | ||
playerSlider.isHidden = true | ||
interactor?.hidePlayerSlider() | ||
} | ||
|
||
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이것도 그냥 궁금한건데 무슨 의미인가여 이거 없으면 어케 되는지 궁금...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그 친구를 window에서 한단계 우선순위를 높여야 탭바에 안가려지더라구요. 탭 바위에 동그라미 보이게 하고 싶어서 우선순위 올린겁니다.