简体   繁体   English

完成后重置 Vimeo 播放器

[英]Reset Vimeo player when finished

How can I reset an embed Vimeo video to how it was onload after it's done playing?如何将嵌入的 Vimeo 视频重置为播放完成后的加载方式?

The Vimeo API offers an unload method Vimeo API 提供了一个卸载方法

player.api("unload")

But it isn't working for non-flash players.但它不适用于非 Flash 播放器。

Using the Vimeo API , you can add an event for finish to trigger the reload. 使用Vimeo API ,您可以添加finish事件以触发重新加载。 The Vimeo API includes a method unload() , but it isn't supported in HTML players . Vimeo API包含一个方法unload() ,但HTML播放器不支持它 Instead, reset the URL in the iframe to return the video to it's original state. 而是重置iframe中的URL以将视频返回到其原始状态。

HTML HTML

<iframe src="//player.vimeo.com/video/77984632?api=1" id="video"></iframe>

JS JS

var iframe = document.getElementById("video"),
    player = $f(iframe);

player.addEvent("ready", function() {        
    player.addEvent('finish', function() {
        player.element.src = player.element.src;
    });
});

unload()现在应该适用于所有玩家。

Variation of Steve Robbins solution, with Vimeo specific solution. Steve Robbins 解决方案的变体,具有 Vimeo 特定解决方案。 You don't have to reach the end of the video, but anytime the user bails out, including clicking on a button:您不必到达视频的结尾,但只要用户退出,包括单击按钮:

Simple Javascript solution with Vimeo Library loaded: https:\/\/player.vimeo.com\/api\/player.js<\/a>加载了 Vimeo 库的简单 Javascript 解决方案: https<\/a> : \/\/player.vimeo.com\/api\/player.js<\/a>

function ResetVideo()
{ 
var Field  = "iframe-video";                   // <iframe id=iframe-video
var iframe = document.getElementById(Field);

var bLoad = LoadVimeoLib();                   // Is the Vimeo lib loaded
if(bLoad > 0)
  { 
  var Videoplayer   = new Vimeo.Player(iframe);
  Videoplayer.pause();                       // Pause the video and audio      
  Videoplayer.setCurrentTime(0);             // Reset the video position
    
  // Reset the video back to the iframe
  VideoSrc = Videoplayer.element.src;        // Save the video source
  Videoplayer.element.src = "";              // Empty the source
  Videoplayer.element.src = VideoSrc;        // Reset the video source
  }
}

function LoadVimeoLib()
{
if (typeof jQuery === 'undefined') 
 {
 alert('no jquery installed');
return 0;
}

var scriptlen = jQuery('script[src="https://player.vimeo.com/api/player.js"]').length;
if (scriptlen  == 0) 
  {
  jQuery.ajax({
    type: "GET",
    url: "https://player.vimeo.com/api/player.js",
    dataType: "script"
  });
  }

 return 1;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM