Oksana
Oksana

Reputation: 119

“This video is unavailable” - html with iframe for WKWebView embedding

I need to embed Youtube video using iframe. According to a test project when I try using youtube_ios_player_helper with function

-(BOOL)loadWithVideoId:(nonnull NSString *)videoId playerVars: (nullable NSDictionary *)playerVars

let vars = ["origin": "http://www.youtube.com"]
playerView.load(withVideoId: "gqbB8-sBuvg", playerVars: vars)

the video is working. If I don't use additional parameters, I see: "This video is unavailable". But for iframe, I only see "This video is unavailable". I'm using the following html:

videoWebView.loadHTMLString("<iframe width=\"\(videoWebView.frame.width)\" height=\"\(videoWebView.frame.height)\" src=\"https://www.youtube.com/embed/gqbB8-sBuvg?enablejsapi=1&origin=\"http://www.youtube.com\"\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowfullscreen> </iframe>", baseURL: nil)

How to fix the iframe embedding?

Upvotes: 1

Views: 2570

Answers (1)

Oksana
Oksana

Reputation: 119

To fix the problem with iframe embedding you don't need to use the YouTube Helper Library. The problem was with baseURL. Instead of receiving nil, there needs to be a link or a path for resources.

For example,

videoWebView.loadHTMLString("<iframe>...</iframe>", baseURL: URL(string: "http://www.youtube.com")!)

Upvotes: 2

Related Questions