Created
June 12, 2020 15:55
-
-
Save Pobe16/90d538f8eaa905c409f5246b5e404e82 to your computer and use it in GitHub Desktop.
ytviewrepresentable coordinator
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 | |
class Coordinator: YouTubePlayerDelegate { | |
// 2 | |
@ObservedObject var playerState: YouTubeControlState | |
init(playerState: YouTubeControlState) { | |
self.playerState = playerState | |
} | |
// 3 | |
func playerReady(_ videoPlayer: YouTubePlayerView) { | |
videoPlayer.play() | |
playerState.videoState = .play | |
} | |
// 4 | |
func playerStateChanged(_ videoPlayer: YouTubePlayerView, playerState: YouTubePlayerState) { | |
switch playerState { | |
case .Playing: | |
self.playerState.videoState = .play | |
case .Paused, .Buffering, .Unstarted: | |
self.playerState.videoState = .pause | |
case .Ended: | |
self.playerState.videoState = .stop | |
// 5 | |
self.playerState.videoID = loadNextVideo() | |
default: | |
print("\(playerState) not implemented") | |
} | |
} | |
} | |
// 6 | |
func makeCoordinator() -> Coordinator { | |
Coordinator(playerState: playerState) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment