UIWebview is not loading youtube videoes in iFrame

亡梦爱人 提交于 2019-12-12 14:13:44

问题


In my app I am using UIWebview to Load Html string which is having Text,Image Url and Videos in iFrame.This was working fine till now but recently I came to know that text and image url are loading fine and the video is not loading.I am just getting the blank space which I have allocated for the video but no sign of video.

The video iFrame which I am getting is this:

<iframe width="100%" height="" src="//www.youtube.com/embed/bhRqrw82P3A" frameborder="0" allowfullscreen></iframe>

Please suggest if something has changed in API.


回答1:


    <iframe src='http://www.youtube.com/embed/bhRqrw82P3A?modestbranding=1&showinfo=0&fs=0' width='300' height='175' frameborder='0' >
    </iframe>

http://jsfiddle.net/tx77b/




回答2:


See this difference:

src="//www.youtube.com/embed/bhRqrw82P3A"

src="http://www.youtube.com/embed/bhRqrw82P3A"

If you want to use first one you have to add "http:" into your URL to make it valid link. You can do it very easy by adding some base URL when loading HTML string into UIWebView

NSURL *baseURL = [NSURL URLWithString:@"http:"];
[self.contentWebView loadHTMLString:myHTMLCode
                            baseURL:baseURL];



回答3:


//www.youtube.com/embed/bhRqrw82P3A uses scheme depends on server (http or https...etc). In local HTML it will point to file://www.youtube.com/embed/bhRqrw82P3A. I make a fake http host for loading:

[webView loadHTMLString:yourHTMLCode baseURL:[NSURL URLWithString:@"http://localhost"]];

This works for me.



来源:https://stackoverflow.com/questions/21277254/uiwebview-is-not-loading-youtube-videoes-in-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!