将Youtube视频嵌入iOS HTML

将Youtube视频嵌入iOS HTML,html,ios,webview,youtube,Html,Ios,Webview,Youtube,我正在使用[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@“html”]isDirectory:NO]]类型的“常见问题解答”将html文件加载到我的webview现在我想将youtube视频嵌入到html文件中。我有这个文件,但不知道要添加什么才能工作。我发现了一些代码,可以将其作为字符串加载,但我需要的是将其

我正在使用
[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@“html”]isDirectory:NO]]类型的“常见问题解答”将html文件加载到我的webview现在我想将youtube视频嵌入到html文件中。我有这个文件,但不知道要添加什么才能工作。我发现了一些代码,可以将其作为字符串加载,但我需要的是将其加载到html文件中。我尝试过在html文件中添加我在其他帖子中找到的相同代码,但它总是作为外部链接出现,而不是嵌入到html文件中。以下是我所拥有的:

<script type="text/javascript" src="http://www.youtube.com/iframe_api"></script>
    <script type="text/javascript">
    function onYouTubeIframeAPIReady()
    {
    ytplayer=new YT.Player('playerId',{events:{onReady:onPlayerReady}})
    }
    function onPlayerReady(a)
    {
    a.target.playVideo();
    }</script>
    <iframe id="playerId" type="text/html" width="250" height="180" src="http://www.youtube.com/embed/9qkXs768JKY?enablejsapi=1&rel=0&playsinline=1&autoplay=1" frameborder="0"></iframe>

我使用此功能在web视图中播放youtube视频:

<iframe class="youtube-player" type="text/html" width="640" height="385" src="http://www.youtube.com/embed/XDJxoVIqdW0" frameborder="0">


对于UIWebView,您需要将
允许InlineMediaPlayback
设置为
,以便在应用程序中显示媒体。在iPhone上默认为
NO


是的,我有类似的东西,但它没有嵌入到webview中。它是在Safari中打开的。不,我的网站上有一个页面(仅)包含该代码。我用loadRequest在应用程序的Web视图中打开它,视频在该视图中播放。
<iframe class="youtube-player" type="text/html" width="640" height="385" src="http://www.youtube.com/embed/XDJxoVIqdW0" frameborder="0">