Created
June 12, 2020 15:07
-
-
Save Pobe16/bf9182813742d9e8f075186bc923a19b to your computer and use it in GitHub Desktop.
ytviewrepresentable update
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
func updateUIView(_ uiView: UIViewType, context: Context) { | |
// 1 | |
guard let videoID = playerState.videoID else { return } | |
// 2 | |
if !(playerState.executeCommand == .idle) && uiView.ready { | |
// 3 | |
switch playerState.executeCommand { | |
case .loadNewVideo: | |
// 4 | |
playerState.executeCommand = .idle | |
uiView.loadVideoID(videoID) | |
case .play: | |
playerState.executeCommand = .idle | |
uiView.play() | |
case .pause: | |
playerState.executeCommand = .idle | |
uiView.pause() | |
case .forward: | |
playerState.executeCommand = .idle | |
// 5 | |
uiView.getCurrentTime { (time) in | |
guard let time = time else {return} | |
uiView.seekTo(Float(time) + 10, seekAhead: true) | |
} | |
case .backward: | |
playerState.executeCommand = .idle | |
uiView.getCurrentTime { (time) in | |
guard let time = time else {return} | |
uiView.seekTo(Float(time) - 10, seekAhead: true) | |
} | |
// 6 | |
default: | |
playerState.executeCommand = .idle | |
print("\(playerState.executeCommand) not yet implemented") | |
} | |
// 7 | |
} else if !uiView.ready { | |
uiView.loadVideoID(videoID) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment