使 YouTube JS API 与 iOS 兼容,处理 embedSWF? [英] Making the YouTube JS API work with iOS, dealing with embedSWF?

查看:31
本文介绍了使 YouTube JS API 与 iOS 兼容,处理 embedSWF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 JS API for YouTube 和显示视频播放器,使用 embedSWF是 Google 在文档中推荐的,如下所示:

 <script type="text/javascript" src="swfobject.js"></script><div id="ytapiplayer">您需要启用 Flash 播放器 8+ 和 JavaScript 才能观看此视频.

<script type="text/javascript">var params = { allowScriptAccess: "always" };var atts = { id: "myytplayer" };swfobject.embedSWF("http://www.youtube.com/v/VIDEO_ID?enablejsapi=1&playerapiid=ytplayer&version=3","ytapiplayer", "425", "356", "8", null,空,参数,atts);

虽然这在我的电脑和 Android 设备上运行良好,但在 iOS 上 ytapiplayer div 不会变成嵌入式播放器,而是只显示其原始内容,即错误消息说 Flash player 8+和JS是必需的.

是否可以让我在 iOS 上使用它?如果是这样,如何?

提前致谢!

解决方案

也许您应该尝试新的 YouTube iframe Player API?https://developers.google.com/youtube/iframe_api_reference

它适用于移动设备,无需考虑 Flash.嵌入示例:

<script type="text/javascript" src="//www.youtube.com/iframe_api"></script>函数 onYouTubePlayerAPIReady() {var videoBox = document.getElementById('video1');videoBox.ytplayer = 新 YT.Player(videoBox, {videoId: 'kXDiGtgPL6E',玩家变量:{//控制:0,wmode:'透明'},高度:'200',宽度:'320'});}

I'm working with the JS API for YouTube and for displaying the video player, use of embedSWF is recommended by Google in the documentation, like this:

  <script type="text/javascript" src="swfobject.js"></script>    

  <div id="ytapiplayer">
    You need Flash player 8+ and JavaScript enabled to view this video.
  </div>

  <script type="text/javascript">

    var params = { allowScriptAccess: "always" };
    var atts = { id: "myytplayer" };
    swfobject.embedSWF("http://www.youtube.com/v/VIDEO_ID?enablejsapi=1&playerapiid=ytplayer&version=3","ytapiplayer", "425", "356", "8", null, null, params, atts);

  </script>

While this works fine on my computer and Android devices, on iOS the ytapiplayer div does not turn into an embedded player but instead just displays its original contents, i.e. the error message saying Flash player 8+ and JS are required.

Is it possible to get my this working on iOS? If so, how?

Thanks in advance!

解决方案

Maybe you should try new YouTube iframe Player API? https://developers.google.com/youtube/iframe_api_reference

It works with mobile devices without thinking about Flash. Embedding example:

<script type="text/javascript" src="//www.youtube.com/iframe_api"></script>

function onYouTubePlayerAPIReady() {
    var videoBox = document.getElementById('video1');
    videoBox.ytplayer = new YT.Player(videoBox, {
        videoId: 'kXDiGtgPL6E',
        playerVars: {
            //controls: 0,
            wmode:'transparent'
        },
        height: '200',
        width: '320'
    });
}

这篇关于使 YouTube JS API 与 iOS 兼容,处理 embedSWF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆