簡體   English   中英

完成后重置 Vimeo 播放器

[英]Reset Vimeo player when finished

如何將嵌入的 Vimeo 視頻重置為播放完成后的加載方式?

Vimeo API 提供了一個卸載方法

player.api("unload")

但它不適用於非 Flash 播放器。

使用Vimeo API ,您可以添加finish事件以觸發重新加載。 Vimeo API包含一個方法unload() ,但HTML播放器不支持它 而是重置iframe中的URL以將視頻返回到其原始狀態。

HTML

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

JS

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

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

unload()現在應該適用於所有玩家。

Steve Robbins 解決方案的變體,具有 Vimeo 特定解決方案。 您不必到達視頻的結尾,但只要用戶退出,包括單擊按鈕:

加載了 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