【问题标题】:youtube video not loading by idyoutube 视频不按 id 加载
【发布时间】:2011-09-03 03:19:33
【问题描述】:

我从代码游乐场http://code.google.com/apis/ajax/playground/?exp=youtube#change_the_playing_video获取代码

我不知道为什么它不能在我的电脑上工作

 '<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>YouTube Player API Sample</title>
<style type="text/css">
  #videoDiv { 
    margin-right: 3px;
  }
  #videoInfo {
    margin-left: 3px;
  }
</style>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
  google.load("swfobject", "2.1");
</script>    
<script type="text/javascript">
  /*
   * Change out the video that is playing
   */

  // Update a particular HTML element with a new value
  function updateHTML(elmId, value) {
    document.getElementById(elmId).innerHTML = value;
  }

  // Loads the selected video into the player.
  function loadVideo() {
    var selectBox = document.getElementById("videoSelection");
    var videoID = selectBox.options[selectBox.selectedIndex].value

    if(ytplayer) {
      ytplayer.loadVideoById(videoID);
    }
  }

  // This function is called when an error is thrown by the player
  function onPlayerError(errorCode) {
    alert("An error occured of type:" + errorCode);
  }

  // This function is automatically called by the player once it loads
  function onYouTubePlayerReady(playerId) {
    ytplayer = document.getElementById("ytPlayer");
    ytplayer.addEventListener("onError", "onPlayerError");
  }

  // The "main method" of this sample. Called when someone clicks "Run".
  function loadPlayer() {
    // The video to load
    var videoID = "ylLzyHk54Z0"
    // Lets Flash from another domain call JavaScript
    var params = { allowScriptAccess: "always" };
    // The element id of the Flash embed
    var atts = { id: "ytPlayer" };
    // All of the magic handled by SWFObject (http://code.google.com/p/swfobject/)
    swfobject.embedSWF("http://www.youtube.com/v/" + videoID + 
                       "&enablejsapi=1&playerapiid=player1", 
                       "videoDiv", "480", "295", "8", null, null, params, atts);
  }
  function _run() {
    loadPlayer();
  }
  google.setOnLoadCallback(_run);
</script>

正在加载...

选择要加载的视频:

YouTube API 概述 忍者猫 拳击长笛 '

【问题讨论】:

    标签: api youtube youtube-api jsapi


    【解决方案1】:

    来自 Google Chromeless API:

    注意:要测试任何这些调用,您必须让文件在网络服务器上运行,因为 Flash 播放器会限制本地文件和互联网之间的调用。 [1]

    您为什么不尝试在线演示? [2]

    [1]http://code.google.com/apis/youtube/js_api_reference.html#GettingStarted

    [2]http://code.google.com/apis/youtube/youtube_player_demo.html?playerType=chromeless&playerVersion=as3

    【讨论】:

      猜你喜欢
      • 2011-05-05
      • 2014-12-20
      • 1970-01-01
      • 1970-01-01
      • 2012-10-06
      • 2020-12-27
      • 1970-01-01
      • 2012-07-09
      • 1970-01-01
      相关资源
      最近更新 更多