Skip to content

Commit

Permalink
Merge pull request insidegui#236 from SoneeJohn/player-controls
Browse files Browse the repository at this point in the history
Update player control based on live streaming
  • Loading branch information
insidegui authored Jun 10, 2017
2 parents b527de4 + e8a4aa5 commit 4af11be
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions PlayerUI/Protocols/PUIPlayerViewDelegates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ public protocol PUIPlayerViewDelegate: class {

public protocol PUIPlayerViewAppearanceDelegate: class {

func playerViewShouldShowTimelineView(_ playerView: PUIPlayerView) -> Bool
func playerViewShouldShowSubtitlesControl(_ playerView: PUIPlayerView) -> Bool
func playerViewShouldShowPictureInPictureControl(_ playerView: PUIPlayerView) -> Bool
func playerViewShouldShowSpeedControl(_ playerView: PUIPlayerView) -> Bool
func playerViewShouldShowAnnotationControls(_ playerView: PUIPlayerView) -> Bool
func playerViewShouldShowBackAndForwardControls(_ playerView: PUIPlayerView) -> Bool
func playerViewShouldShowTimestampLabels(_ playerView: PUIPlayerView) -> Bool
func playerViewShouldShowExternalPlaybackControls(_ playerView: PUIPlayerView) -> Bool
func playerViewShouldShowFullScreenButton(_ playerView: PUIPlayerView) -> Bool

Expand Down
2 changes: 2 additions & 0 deletions PlayerUI/Views/PUIPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,8 @@ public final class PUIPlayerView: NSView {
updateExternalPlaybackControlsAvailability()

fullScreenButton.isHidden = !d.playerViewShouldShowFullScreenButton(self)
timelineView.isHidden = !d.playerViewShouldShowTimelineView(self)
timeLabelsContainerView.isHidden = !d.playerViewShouldShowTimestampLabels(self)
}

fileprivate func updateExternalPlaybackControlsAvailability() {
Expand Down
45 changes: 44 additions & 1 deletion WWDC/VideoPlayerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ final class VideoPlayerViewController: NSViewController {
self.disposeBag = DisposeBag()

updateUI()
resetAppearanceDelegate()
}
}

Expand Down Expand Up @@ -109,13 +110,16 @@ final class VideoPlayerViewController: NSViewController {
super.viewDidLoad()

playerView.delegate = self

resetAppearanceDelegate()
reset(oldValue: nil)
updateUI()

NotificationCenter.default.addObserver(self, selector: #selector(annotationSelected(notification:)), name: .TranscriptControllerDidSelectAnnotation, object: nil)
}

func resetAppearanceDelegate() {
playerView.appearanceDelegate = self
}
func reset(oldValue: AVPlayer?) {
if let oldPlayer = oldValue {
if let boundaryObserver = boundaryObserver {
Expand Down Expand Up @@ -275,6 +279,45 @@ extension VideoPlayerViewController: PUIPlayerViewDelegate {

}

extension VideoPlayerViewController: PUIPlayerViewAppearanceDelegate {

func playerViewShouldShowSubtitlesControl(_ playerView: PUIPlayerView) -> Bool {
return true
}

func playerViewShouldShowPictureInPictureControl(_ playerView: PUIPlayerView) -> Bool {
return true
}

func playerViewShouldShowSpeedControl(_ playerView: PUIPlayerView) -> Bool {
return !self.sessionViewModel.sessionInstance.isCurrentlyLive
}

func playerViewShouldShowAnnotationControls(_ playerView: PUIPlayerView) -> Bool {
return !self.sessionViewModel.sessionInstance.isCurrentlyLive
}

func playerViewShouldShowBackAndForwardControls(_ playerView: PUIPlayerView) -> Bool {
return !self.sessionViewModel.sessionInstance.isCurrentlyLive
}

func playerViewShouldShowExternalPlaybackControls(_ playerView: PUIPlayerView) -> Bool {
return true
}

func playerViewShouldShowFullScreenButton(_ playerView: PUIPlayerView) -> Bool {
return true
}

func playerViewShouldShowTimelineView(_ playerView: PUIPlayerView) -> Bool {
return !self.sessionViewModel.sessionInstance.isCurrentlyLive
}

func playerViewShouldShowTimestampLabels(_ playerView: PUIPlayerView) -> Bool {
return !self.sessionViewModel.sessionInstance.isCurrentlyLive
}
}

extension Transcript {

func timecodesWithTimescale(_ timescale: Int32) -> [NSValue] {
Expand Down

0 comments on commit 4af11be

Please sign in to comment.