我的Javascript / jQuery函数只运行一次,只有函数的底部部分正常工作。我可以翻转订单,然后另一件就行了。我缺少什么(使用Buzz音频API播放和暂停方法)?
var $playFromPlayerBar = $('.main-controls .play-pause');
var togglePlayFromPlayerBar = function(){
if (currentSoundFile.pause() && $playFromPlayerBar.click){
var $songNumberCell = getSongNumberCell(currentlyPlayingSongNumber);
$songNumberCell.html(pauseButtonTemplate);
$playFromPlayerBar.html(playerBarPauseButton);
currentSoundFile.play();
}
if (currentSoundFile.play() && $playFromPlayerBar.click){
var $songNumberCell = getSongNumberCell(currentlyPlayingSongNumber);
$songNumberCell.html(playButtonTemplate);
$playFromPlayerBar.html(playerBarPlayButton);
currentSoundFile.pause();
}
};
//load album when window loads
$(document).ready(function() {
$playFromPlayerBar.click(togglePlayFromPlayerBar);
});
答案 0 :(得分:1)
这里的绑定可能有问题,尝试这样的事情:
$playFromPlayerBar.click
此外,您需要调用点击功能,并在条件表达式中执行此操作:
$playFromPlayerBar.click()
你应该这样做:
fsx
答案 1 :(得分:0)
啊哈!!我想通了。
var togglePlayFromPlayerBar = function(){
if ($playFromPlayerBar.click){
var $songNumberCell = getSongNumberCell(currentlyPlayingSongNumber);
if (currentSoundFile.isPaused()){
$songNumberCell.html(pauseButtonTemplate);
$playFromPlayerBar.html(playerBarPauseButton);
} else {
$songNumberCell.html(playButtonTemplate);
$playFromPlayerBar.html(playerBarPlayButton);
}
currentSoundFile.togglePlay();
}
};
//load album when window loads
$(document).ready(function() {
$playFromPlayerBar.click(togglePlayFromPlayerBar);
});