2012-03-08 111 views
3

我有一個vimeo視頻,當用戶點擊一個div時加載。jquery和vimeo:不會自動播放

<div class="vimeobox" ID="vimeo-ID-goes-here"></div> 

這裏是我的javascript:

$(".vimeobox").click(function() { 

     var iframe = "<iframe />"; 
     var id = $(this).attr('id'); // 
     var url = "http://player.vimeo.com/video/" + id + "?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=1"; 

     var width = 700; 
     var height = 394; 
     var frameborder = 0; 

     $(iframe, { 
      name: 'videoframe', 
      id: 'videoframe', 
      src: url, 
      width: width, 
      height: height, 
      frameborder: frameborder, 
      type: 'text/html', 
      allowfullscreen: true, 
      webkitAllowFullScreen: true, 
      mozallowfullscreen: true 
     }).css({'position': 'absolute', 'top': '0', 'left': '0'}).appendTo(this); 

     $(this).find('img').fadeOut(function() { $(this).remove(); 

     }); 

    }); 

被點擊(刪除預覽圖像)div時VIMEO播放器出現......但視頻沒有自動播放。

我不知道問題是什麼。我爲youtube播放器使用幾乎相同的代碼(減去url變量)並自動播放?

+0

完全工作!我想知道爲什麼鏈接在vimeo嵌入代碼中以這種方式呈現? – redconservatory 2012-03-08 18:34:38

+0

我不知道,通常這是用作分隔符的'?',所以你不必轉義&符號(但是隻要HTTP服務器有很多可用作分隔符的有效字符支持他們)。 – talnicolas 2012-03-08 18:46:57

回答

3

只需將您的網址中的&amp;更改爲?即可。

0

這裏的其他答案確實是正確的,但如果您在移動設備上遇到問題並且自動播放功能在運行設備(Android/iOS和Windows Mobile)上無法運行,在寫這篇文章的時候。

如果有人想出了強制自動播放功能的黑客請發佈。

0

您也可以手動添加以下參數到您的嵌入代碼做到這一點: 循環= 1個 自動播放= 1 如果你有一個特定的頁面上有多個視頻自動播放,你就還需要包括這個參數: autopause = 0