Skip to content

Instantly share code, notes, and snippets.

View Pobe16's full-sized avatar

Mikolaj Lukasik Pobe16

View GitHub Profile
@Pobe16
Pobe16 / ytviewrepresentable_coordinator.swift
Created June 12, 2020 15:55
ytviewrepresentable coordinator
// 1
class Coordinator: YouTubePlayerDelegate {
// 2
@ObservedObject var playerState: YouTubeControlState
init(playerState: YouTubeControlState) {
self.playerState = playerState
}
// 3
@Pobe16
Pobe16 / ytviewrepresentable.swift
Created June 12, 2020 15:07
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
@Pobe16
Pobe16 / ytviewrepresentable1.swift
Last active June 12, 2020 14:14
YTViewRepresentable step 1
import SwiftUI
import UIKit
import YouTubePlayer
// 1
struct YouTubeView: UIViewRepresentable {
// 2
typealias UIViewType = YouTubePlayerView
// 3
@Pobe16
Pobe16 / YouTubeView.swift
Last active May 24, 2022 21:57
YouTubeView UIViewRepresentable
import SwiftUI
import UIKit
import YouTubePlayer
final class YouTubeView: UIViewRepresentable {
typealias UIViewType = YouTubePlayerView
@ObservedObject var playerState: YouTubeControlState
@Pobe16
Pobe16 / YouTubeControlState.swift
Last active June 12, 2020 12:58
Controller Object for YouTube Video
// 1
enum playerCommandToExecute {
case loadNewVideo
case play
case pause
case forward
case backward
case stop
case idle
}