diff --git a/Course/Course/Presentation/Unit/CourseUnitView.swift b/Course/Course/Presentation/Unit/CourseUnitView.swift index 484fdda9f..c74f0e7b0 100644 --- a/Course/Course/Presentation/Unit/CourseUnitView.swift +++ b/Course/Course/Presentation/Unit/CourseUnitView.swift @@ -50,10 +50,10 @@ public struct CourseUnitView: View { let data = Array(viewModel.verticals[viewModel.verticalIndex].childs.enumerated()) ForEach(data, id: \.offset) { index, block in VStack(spacing: 0) { - if index >= viewModel.index - 1 && index <= viewModel.index + 1 { switch LessonType.from(block) { // MARK: YouTube case let .youtube(url, blockID): + if index >= viewModel.index - 1 && index <= viewModel.index + 1 { if viewModel.connectivity.isInternetAvaliable { YouTubeView( name: block.displayName, @@ -71,8 +71,12 @@ public struct CourseUnitView: View { } else { NoInternetView(playerStateSubject: playerStateSubject) } + } else { + EmptyView() + } // MARK: Encoded Video case let .video(encodedUrl, blockID): + if index == viewModel.index { let url = viewModel.urlForVideoFileOrFallback( blockId: blockID, url: encodedUrl @@ -94,23 +98,33 @@ public struct CourseUnitView: View { } else { NoInternetView(playerStateSubject: playerStateSubject) } + } // MARK: Web case .web(let url): + if index >= viewModel.index - 1 && index <= viewModel.index + 1 { if viewModel.connectivity.isInternetAvaliable { WebView(url: url, viewModel: viewModel) } else { NoInternetView(playerStateSubject: playerStateSubject) } + } else { + EmptyView() + } // MARK: Unknown case .unknown(let url): + if index >= viewModel.index - 1 && index <= viewModel.index + 1 { if viewModel.connectivity.isInternetAvaliable { UnknownView(url: url, viewModel: viewModel) Spacer() } else { NoInternetView(playerStateSubject: playerStateSubject) } + } else { + EmptyView() + } // MARK: Discussion case let .discussion(blockID, blockKey, title): + if index >= viewModel.index - 1 && index <= viewModel.index + 1 { if viewModel.connectivity.isInternetAvaliable { VStack { if showDiscussion { @@ -131,10 +145,11 @@ public struct CourseUnitView: View { } else { NoInternetView(playerStateSubject: playerStateSubject) } + } else { + EmptyView() } - } else { - EmptyView() - } + } + } .frame( width: isHorizontal ? reader.size.width - 16 : reader.size.width, diff --git a/Course/Course/Presentation/Video/EncodedVideoPlayer.swift b/Course/Course/Presentation/Video/EncodedVideoPlayer.swift index 233469250..52ddb98cd 100644 --- a/Course/Course/Presentation/Video/EncodedVideoPlayer.swift +++ b/Course/Course/Presentation/Video/EncodedVideoPlayer.swift @@ -115,6 +115,9 @@ public struct EncodedVideoPlayer: View { } } }.padding(.horizontal, isHorizontal ? 0 : 8) + .onDisappear { + viewModel.controller.player?.allowsExternalPlayback = false + } } private func pauseScrolling() { diff --git a/Course/Course/Presentation/Video/PlayerViewController.swift b/Course/Course/Presentation/Video/PlayerViewController.swift index 01a27e640..bbabc73f4 100644 --- a/Course/Course/Presentation/Video/PlayerViewController.swift +++ b/Course/Course/Presentation/Video/PlayerViewController.swift @@ -73,6 +73,7 @@ struct PlayerViewController: UIViewControllerRepresentable { if asset?.url.absoluteString != videoURL?.absoluteString { if playerController.player == nil { playerController.player = AVPlayer() + playerController.player?.allowsExternalPlayback = true } playerController.player?.replaceCurrentItem(with: AVPlayerItem(url: videoURL!)) addPeriodicTimeObserver(playerController, currentProgress: { progress, seconds in diff --git a/Course/Course/Presentation/Video/YouTubeVideoPlayerViewModel.swift b/Course/Course/Presentation/Video/YouTubeVideoPlayerViewModel.swift index 06bc69f75..9b4440458 100644 --- a/Course/Course/Presentation/Video/YouTubeVideoPlayerViewModel.swift +++ b/Course/Course/Presentation/Video/YouTubeVideoPlayerViewModel.swift @@ -80,7 +80,7 @@ public class YouTubeVideoPlayerViewModel: VideoPlayerViewModel { playerStateSubject.sink(receiveValue: { [weak self] state in switch state { case .pause: - self?.youtubePlayer.pause() + self?.youtubePlayer.stop() case .kill, .none: break }