YouTube 视频未按 ID 加载

发布于 2024-11-09 17:40:06 字数 2550 浏览 3 评论 0原文

我从代码游乐场 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 Overview Ninja Cat Beatboxing Flute '

i get the code from code playground http://code.google.com/apis/ajax/playground/?exp=youtube#change_the_playing_video

i dont know why it's not working in my pc

 '<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>

Loading...

Select a video to load:

YouTube API Overview
Ninja Cat
Beatboxing Flute

'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沧桑㈠ 2024-11-16 17:40:06

来自 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

From Google Chromeless API:

Note: To test any of these calls, you must have your file running on a webserver, as the Flash player restricts calls between local files and the internet. [1]

Why don't you try on-line demo? [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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文