Skip to content

Instantly share code, notes, and snippets.

@Pobe16
Created June 12, 2020 15:07
Show Gist options
  • Save Pobe16/bf9182813742d9e8f075186bc923a19b to your computer and use it in GitHub Desktop.
Save Pobe16/bf9182813742d9e8f075186bc923a19b to your computer and use it in GitHub Desktop.
ytviewrepresentable update
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