In my app I use WKWebView
and the user can go to different websites like google, wikipedia, vimeo, etc. The issue is if the user decides to go to https://www.youtube.com
, when the user taps a thumbnail to play it, it doesn't autoplay because I don't have the videoId (eg. "https://youtu.be/MpvshzR6tNk"
), I just have the the youtube website url
For example:
func loadRequest() { let strThatUserEntered = "https://youtube.com" let urlStr = "strThatUserEntered" guard let url = URL(string: urlStr), let request = URLRequest(url: url) else { return } wkWebView.load(request) wkWebView.allowsBackForwardNavigationGestures = true }
Now when the user selects a random thumbnail, the video loads, the youtube play button appears, and when it's pressed, I get: An error occurred, please try again later
(this video definitely works)
How can I enable autoplay on any selected youtube thumbnail , if I don't have the videoID?
code:
override func viewDidLoad() super.viewDidLoad() let webConfiguration = WKWebViewConfiguration() webConfiguration.allowsInlineMediaPlayback = true webConfiguration.mediaTypesRequiringUserActionForPlayback = [] wkWebView = WKWebView(frame: .zero, configuration: webConfiguration) wkWebView.navigationDelegate = self wkWebView.uiDelegate = self // pin wkWebView anchors to screen loadRequest() }