Skip to content

Instantly share code, notes, and snippets.

@siempay
Created June 19, 2022 11:11
Show Gist options
  • Save siempay/51a8ab5a17256cd2193c8ad12640f1ae to your computer and use it in GitHub Desktop.
Save siempay/51a8ab5a17256cd2193c8ad12640f1ae to your computer and use it in GitHub Desktop.
SwiftUI: How to add YouTube VideoPlayer
//
// Created by Brahim Elmssilha on 16/6/2022.
// Email: [email protected]
//
struct YoutubeVideoView: UIViewRepresentable {
var youtubeVideoID: String
func makeUIView(context: Context) -> WKWebView {
WKWebView()
}
func updateUIView(_ uiView: WKWebView, context: Context) {
let path = "https://www.youtube.com/embed/\(youtubeVideoID)"
guard let url = URL(string: path) else { return }
uiView.backgroundColor = UIColor(named: "b2")
uiView.scrollView.isScrollEnabled = false
uiView.load(.init(url: url))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment