我在使用带有多个视频的Vimeo API时遇到了一些麻烦。我正在使用的代码暂停
<audio id="audio-player" autoplay="autoplay" loop>
<source src="music/peanutbutter.mp3" type="audio/mpeg">
</audio>
播放,但它只适用于第一个视频iframe。如果我单击第2,第3或第4个vimeo iframe上的“播放”按钮,则遗憾的是它不会暂停页面上的音频。这可能是一个简单的修复,但我想疯了解决这个问题。谢谢!
<script src="http://a.vimeocdn.com/js/froogaloop2.min.js"></script>
<script type="text/javascript">
$(function(){
var vimeoPlayer = document.querySelector('iframe');
$f(vimeoPlayer).addEvent('ready', ready);
function ready(player_id) {
froogaloop = $f(player_id);
function setupEventListeners() {
function onPlay() {
froogaloop.addEvent('play',
function(){
$("#audio-player")[0].pause();
$("#header-button-sound-play").hide();
$("#header-button-sound-pause").show();
});
}
onPlay();
}
setupEventListeners();
}
})
</script>
<div id="dwf-trailer" class="content"><iframe id="player_1" src="http://player.vimeo.com/video/35740045?api=1&player_id=player_1" width="745" height="393" frameborder="0"></iframe></div>
<div id="inkpaper-watch" class="content"><iframe id="player_2" src="http://player.vimeo.com/video/33359230?api=1&player_id=player_2" width="745" height="393" frameborder="0"></iframe></div>
<div id="ramon-watch" class="content"><iframe id="player_3" src="http://player.vimeo.com/video/44427351?api=1&player_id=player_3" width="745" height="393" frameborder="0"></iframe></div>
<div id="thatsunday-watch" class="content"><iframe id="player_4" src="http://player.vimeo.com/video/46602515?api=1&player_id=player_4" width="745" height="393" frameborder="0"></iframe></div>
答案 0 :(得分:2)
没关系!弄清楚了。
替换这段代码
$f(vimeoPlayer).addEvent('ready', ready);
有了这个
jQuery('iframe').each(function(){
Froogaloop(this).addEvent('ready', ready);
});
解决了这个问题!所以工作的JavaScript代码是
<script type="text/javascript">
$(function(){
jQuery('iframe').each(function(){
Froogaloop(this).addEvent('ready', ready);
});
function ready(player_id) {
froogaloop = $f(player_id);
function setupEventListeners() {
function onPlay() {
froogaloop.addEvent('play',
function(){
$("#audio-player")[0].pause();
$("#header-button-sound-play").hide();
$("#header-button-sound-pause").show();
});
}
onPlay();
}
setupEventListeners();
}
})
</script>
谢谢 http://labs.funkhausdesign.com/examples/vimeo/froogaloop2-api-basics.html
寻求帮助!