Created
June 19, 2022 11:11
-
-
Save siempay/51a8ab5a17256cd2193c8ad12640f1ae to your computer and use it in GitHub Desktop.
SwiftUI: How to add YouTube VideoPlayer
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
// | |
// 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