我正在尝试在Javascript上构建一个Swing Era点唱机。几乎一切都有效,除了'针'。我希望我不是唯一仍然使用乙烯基的人!可以说暂停按钮应该能够从音频暂停的位置恢复,就像抬起针并将其放在同一位置一样。它现在只能暂停。
这是JS代码,或者我认为是相关的摘录:
var playtext = $("div#play").text()
var playing = false
function Jukebox(){
this.tune = $("audio")[0];
Jukebox.prototype.play = function(){
this.tune.play();
playing = true;
}
Jukebox.prototype.pause = function(){
this.tune.pause(); //Apparently, pause is a built-in function?!
playing = false;
}
Jukebox.prototype.needle = function(){
if (playing = true) {
this.tune.pause();
playing = false;
}
if (playing = false) {
this.tune.play();
playing = true; //After it is paused, it cannot play again?! Why?
}
}
答案 0 :(得分:0)
查看此声明
if(playing === true)
而不是
if(playing = true)
答案 1 :(得分:0)
我明白了。我在这里使用冗余语言。答案是:
Jukebox.prototype.needle = function(){
if (playing) {
this.tune.pause();
playing = false;
}
else {
this.tune.play();
playing = true; //After it is paused, it cannot play again?! Why?
}