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 |
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 |
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
import SwiftUI | |
import UIKit | |
import YouTubePlayer | |
// 1 | |
struct YouTubeView: UIViewRepresentable { | |
// 2 | |
typealias UIViewType = YouTubePlayerView | |
// 3 |
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
import SwiftUI | |
import UIKit | |
import YouTubePlayer | |
final class YouTubeView: UIViewRepresentable { | |
typealias UIViewType = YouTubePlayerView | |
@ObservedObject var playerState: YouTubeControlState | |
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 | |
} |