Last active
June 12, 2020 12:58
-
-
Save Pobe16/c7d91d61a6de2cb1f48f03955448fcc8 to your computer and use it in GitHub Desktop.
Controller Object for YouTube Video
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1 | |
enum playerCommandToExecute { | |
case loadNewVideo | |
case play | |
case pause | |
case forward | |
case backward | |
case stop | |
case idle | |
} | |
// 2 | |
class YouTubeControlState: ObservableObject { | |
// 3 | |
@Published var videoID: String? // = "qRC4Vk6kisY" | |
{ | |
// 4 | |
didSet { | |
self.executeCommand = .loadNewVideo | |
} | |
} | |
// 5 | |
@Published var videoState: playerCommandToExecute = .loadNewVideo | |
// 6 | |
@Published var executeCommand: playerCommandToExecute = .idle | |
// 7 | |
func playPauseButtonTapped() { | |
if videoState == .play { | |
pauseVideo() | |
} else if videoState == .pause { | |
playVideo() | |
} else { | |
print("Unknown player state, attempting playing") | |
playVideo() | |
} | |
} | |
// 8 | |
func playVideo() { | |
executeCommand = .play | |
} | |
func pauseVideo() { | |
executeCommand = .pause | |
} | |
func forward() { | |
executeCommand = .forward | |
} | |
func backward() { | |
executeCommand = .backward | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment