我找到了一种使用自定义按钮播放和暂停 vimeo 视频的解决方案,但我现在已将按钮放在一个名为 buttonHolder 的单独 div 中,我似乎无法获得正确的途径来让按钮在他们自己的 div 中工作.
我真的很感激任何帮助。
我的 html 将是:
玩家 1
<div class="buttonHolder">
<img class="simple" id="api_play" src="test.jpg" />
<img class="simple" id="api_pause" src="test.jpg" />
</div>
</div>
</div>
<div>
<div>
<h1>Player 2</h1>
<div class="api_output"></div>
<iframe id="player_2" src="http://player.vimeo.com/video/3718294?js_api=1&js_swf_id=player_2" width="500" height="281" frameborder="0"></iframe>
<div class="buttonHolder">
<img class="simple" id="api_play" src="test.jpg" />
<img class="simple" id="api_pause" src="test.jpg" />
</div>
</div>
</div>
我的jQuery代码是:
var VimeoEmbed = {};
//Called on document ready
VimeoEmbed.init = function(e)
{
//Listen to the load event for all the iframes on the page
$('iframe').each(function(index, iframe){
iframe.addEvent('onLoad', VimeoEmbed.vimeo_player_loaded);
});
};
//EVENT CALLBACKS
/*
* Called when the player finishes loading. The JavaScript API is only available
* after this event fires.
*
* @param player_id (String): ID of the iframe which has finished loading.
*/
VimeoEmbed.vimeo_player_loaded = function(player_id)
{
$('#'+player_id).prev('.api_output').append('VimeoEmbed.vimeo_player_loaded ' + player_id+'<br/>');
var loop = 0;
var volume = 100;
//Simple Buttons
$('#'+player_id).nextAll('img.simple').bind('click', {'player_id': player_id}, function(e){
var iframe = $('#'+e.data.player_id).get(0);
iframe.api( $(e.target).attr('id'), null );
});
//API EVENT LISTENERS
VimeoEmbed.setupAPIEventListeners($('#'+player_id).get(0));
};
//On document ready
$(document).ready(VimeoEmbed.init);
我认为需要编辑的代码如下,但我尝试了多种解决方案,但没有成功。
//Simple Buttons
$('#'+player_id).nextAll('img.simple').bind('click', {'player_id': player_id}, function(e){
var iframe = $('#'+e.data.player_id).get(0);
iframe.api( $(e.target).attr('id'), null );
});