1
votes

I have a WebView in my iOS app. This webView is loading an web page that contains a youtubeVideo using

myWebView.loadHTMLString

The YouTube-video appears good but when I click to play, this show the "not available" message.

The video is loaded in the html webPage using amp:

<script async custom-element="amp-youtube" src="https://cdn.ampproject.org/v0/amp-youtube-0.1.js"></script>

<amp-youtube width="480"
  height="270"
  layout="responsive"
  data-videoid="lBTCB7yLs8Y">
</amp-youtube>

I can see that the url request then script load the html with shouldStartLoadWithRequest delegate webView function and is the embed url video: https://www.youtube.com/embed/lBTCB7yLs8Y?enablejsapi=1&amp=1&playsinline=1

When I added a YouTube video into a webView on another app like this, I only need add YouTube url in baseURL and this works correctly...:

wk.loadHTMLString("<iframe height=\"315\" src=\"https://www.youtube.com/embed/4CEflj1qQ8M?enablejsapi=1&origin=http://example.com\" style=\"width: 100%; height: 100%; position: absolute; top: 0px; left: 0px;\" width=\"560\"></iframe>", baseURL: URL(string : "www.youtube.com"))

How can now play the video correctly? Thanks!

1

1 Answers