Skip to content
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

Screencasting (enable by default) #144

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions Course/Course/Presentation/Unit/CourseUnitView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions Course/Course/Presentation/Video/EncodedVideoPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ public struct EncodedVideoPlayer: View {
}
}
}.padding(.horizontal, isHorizontal ? 0 : 8)
.onDisappear {
viewModel.controller.player?.allowsExternalPlayback = false
}
}

private func pauseScrolling() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down