【问题标题】:Action when youtube video is ended!youtube视频结束时的动作!
【发布时间】:2011-05-29 12:32:42
【问题描述】:

我有一个带有 youtube ID 的数据库。 现在我想播放第一个视频,当视频结束时我想去 http://www.foo.com/index.php?play=1 。所以它将播放下一个 youtube 视频。该视频完成后,它将转到http://www.foo.com/index.php?play=2 ...。我已经尝试过在 x(x 是视频的持续时间)秒后刷新页面的时间。但是当用户点击暂停按钮时,它会提前刷新。

有人可以帮助我吗?

【问题讨论】:

  • 您需要找到一个支持 youtube 的播放器,该播放器可以使用 javascript 进行接口,并且还可以在视频完成时触发事件。然后您可以使用 AJAX 调用来获取下一个视频的 URL 并将其传递给播放器。
  • 看看 YouTube JavaScript Player API,它应该有你需要的一切。 code.google.com/apis/youtube/js_api_reference.html

标签: php javascript youtube youtube-api


【解决方案1】:

嗯,您可以使用 YouTube JavaScript API 播放器。该播放器将触发播放结束、播放暂停和视频提示等事件。您可以在播放结束事件中挂钩一个函数。查看YouTube JavaScript Player API Reference 并向下滚动到events 部分。

【讨论】:

    【解决方案2】:

    解决方案(在我的 wordpress 网站中工作):下载并安装到您的网站 - http://www.tikku.com/jquery-youtube-tubeplayer-plugin

    然后在您的页面中插入此代码
    但要更改
    1) yoursite.com 到您的
    2) alert("Hello"); 到您想要的功能;
    3) DkoeNLuMbcI 到您的视频 ID;

    <div id="youtube-player-container" style="float:right"> </div>
    <script type="text/javascript" src="http://yoursite.com/folder/jQuery.tubeplayer.min.js"></script>
    <script type="text/javascript">
    jQuery("#youtube-player-container").tubeplayer({
        width: 422, // the width of the player
        height: 285, // the height of the player
        allowFullScreen: "true", // true by default, allow user to go full screen
        initialVideo: "DkoeNLuMbcI?autoplay=1", // the video that is loaded into the player
        preferredQuality: "default",// preferred quality: default, small, medium, large, hd720
        onPlay: function(id){}, // after the play method is called
        onPause: function(){}, // after the pause method is called
        onStop: function(){}, // after the player is stopped
        onSeek: function(time){}, // after the video has been seeked to a defined point
        onMute: function(){}, // after the player is muted
        onPlayerEnded: function(){ alert("Hello"); },
        onUnMute: function(){} // after the player is unmuted
    });
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-02
      • 2013-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多