【问题标题】:Vimeo froogaloop conflict with pluginVimeo froogaloop 与插件冲突
【发布时间】:2015-01-28 08:06:54
【问题描述】:

我正在使用插件Vimeowrap Playlist 制作来自某个频道的视频播放列表。这工作得很好,但现在我需要跟踪视频的事件:播放、暂停等。当我使用 froogaloop 执行此操作时,我收到错误 Cannot read property 'getAttribute' of undefined。不知何故,froogaloop 与 Vimeowrap 脚本冲突。谁能帮我解决这个问题?

这是插件代码:

vimeowrap('player').setup({
    urls: [
        'https://vimeo.com/channels/trocadero'
    ],
    height:363,
    item: 5,
    plugins: {
        'playlist':{
            position:'right',
            size:340
        }
    },



});

这是我整个问题的jsfiddle

【问题讨论】:

标签: jquery vimeo vimeo-api vimeo-player froogaloop


【解决方案1】:

我设法解决了我的问题...这是jsfiddle 解决方案。

var vimeoPlayers = [];

function VimeoPlayer (playerId) {
var iframe = $('#' + playerId),
  contentWindow = iframe[0].contentWindow,
  targetOriginUrl = iframe.attr('src').split('?')[0];
console.log(iframe);
console.log(contentWindow);
console.log(targetOriginUrl);

contentWindow.postMessage({ 'method': 'addEventListener', 'value': 'pause' }, "http:"+targetOriginUrl);
contentWindow.postMessage({ 'method': 'addEventListener', 'value': 'play' }, "http:"+targetOriginUrl);

return {
play: function () {
    contentWindow.postMessage({ 'method': 'play' }, "http:"+targetOriginUrl);

},

pause: function() {
  contentWindow.postMessage({ 'method': 'pause' }, "http:"+targetOriginUrl);

},

unload: function() {
  contentWindow.postMessage({ 'method': 'unload' }, "http:"+targetOriginUrl);
}
}
}

// Listen for postMessage events
$(window).on('message', function(e) {
var data = $.parseJSON(e.originalEvent.data);

if (data.event === 'ready') {
var vimeoPlayer = new VimeoPlayer(data.player_id);

vimeoPlayers.push(vimeoPlayer);
}
if(data.event==='play'){
   console.log('play');
 }
 if(data.event==='pause'){
   console.log('pause');
 }

 console.log(data);
});



$('.vimeo-controls .pause-all').on('click', function () {
for (var i = 0; i < vimeoPlayers.length; i++) {
vimeoPlayers[i].pause();
}
 });

$('.vimeo-controls .play-all').on('click', function () {
for (var i = 0; i < vimeoPlayers.length; i++) {
vimeoPlayers[i].play();
}
 });

$('.vimeo-controls .unload-all').on('click', function () {
for (var i = 0; i < vimeoPlayers.length; i++) {
 vimeoPlayers[i].unload();
 }
   });

【讨论】:

  • 您能否简要介绍一下您的解决方案是什么?对您的问题进行手动比较不是很有帮助。
猜你喜欢
  • 1970-01-01
  • 2011-08-25
  • 1970-01-01
  • 2015-04-06
  • 2011-06-18
  • 1970-01-01
  • 2013-02-23
  • 2012-04-09
相关资源
最近更新 更多