Parse stop music statement, fix music loop
This commit is contained in:
parent
aa485218db
commit
983709e80a
@ -70,7 +70,7 @@ Parser.prototype.statement = function() {
|
|||||||
if (this.match(token, TokenType.SCENE)) return this.scene();
|
if (this.match(token, TokenType.SCENE)) return this.scene();
|
||||||
if (this.match(token, TokenType.PLAY)) return this.play();
|
if (this.match(token, TokenType.PLAY)) return this.play();
|
||||||
// if (this.match(token, TokenType.QUEUE)) return this.queue();
|
// if (this.match(token, TokenType.QUEUE)) return this.queue();
|
||||||
// if (this.match(token, TokenType.STOP)) return this.stop();
|
if (this.match(token, TokenType.STOP)) return this.stop();
|
||||||
if (this.match(token, TokenType.SHOW)) return this.show();
|
if (this.match(token, TokenType.SHOW)) return this.show();
|
||||||
if (this.match(token, TokenType.HIDE)) return this.hide();
|
if (this.match(token, TokenType.HIDE)) return this.hide();
|
||||||
|
|
||||||
@ -328,6 +328,22 @@ Parser.prototype.playAmbience = function() {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Parser.prototype.stop = function() {
|
||||||
|
if (this.match(TokenType.MUSIC)) {
|
||||||
|
var fade = this.matchFade();
|
||||||
|
ViewActivity.getInstance().stopMusic(fade);
|
||||||
|
}
|
||||||
|
if (this.match(TokenType.SOUND) || this.match(TokenType.SOUNDLOOP)) {
|
||||||
|
var fade = this.matchFade();
|
||||||
|
// ViewActivity.getInstance().stopSound(fade);
|
||||||
|
}
|
||||||
|
if (this.match(TokenType.AMBIENCE)) {
|
||||||
|
var fade = this.matchFade();
|
||||||
|
// ViewActivity.getInstance().stopAmbience(fade);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
Parser.prototype.menu = function() {
|
Parser.prototype.menu = function() {
|
||||||
// menu: title?
|
// menu: title?
|
||||||
this.consume(TokenType.COLON);
|
this.consume(TokenType.COLON);
|
||||||
|
@ -10,6 +10,7 @@ function Views(parser) {
|
|||||||
|
|
||||||
this.musicPlayerAudio = new Audio();
|
this.musicPlayerAudio = new Audio();
|
||||||
this.soundPlayerAudio = new Audio();
|
this.soundPlayerAudio = new Audio();
|
||||||
|
this.musicQueue = new Array();
|
||||||
|
|
||||||
this.backgroundName = "";
|
this.backgroundName = "";
|
||||||
this.backgroundType = "";
|
this.backgroundType = "";
|
||||||
@ -30,6 +31,8 @@ function Views(parser) {
|
|||||||
$('#menu').hide();
|
$('#menu').hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Views.prototype.NO_FADE = new FadeInfo();
|
||||||
|
|
||||||
Views.prototype.getInstance = function () {
|
Views.prototype.getInstance = function () {
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
@ -320,13 +323,38 @@ Views.prototype.showGameMenuDialog = function (menu) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Views.prototype.music = function (name, fade) {
|
Views.prototype.music = function (name, fade) {
|
||||||
// !musicPlayerAudio.paused;
|
try {
|
||||||
this.musicPlayerAudio.src = PathResolver.music(name);
|
this.stopMusic(this.musicPlayerAudio.fade);
|
||||||
this.musicPlayerAudio.play();
|
this.musicPlayerAudio.src = PathResolver.music(name);
|
||||||
if (fade.fadeIn || fade.fadeOut) {
|
this.musicPlayerAudio.fade = fade;
|
||||||
var startVolume = fade.fadeIn ? 0.0 : 1.0;
|
var views = this;
|
||||||
$(this.musicPlayerAudio).prop("volume", startVolume);
|
this.musicPlayerAudio.addEventListener('ended', function () {
|
||||||
var targetVolume = fade.fadeIn ? 1.0 : 0.0;
|
if (views.musicQueue.length > 0) {
|
||||||
$(this.musicPlayerAudio).animate({volume: targetVolume}, fade.duration * 1000);
|
views.music(views.musicQueue.pop(), views.NO_FADE);
|
||||||
|
} else {
|
||||||
|
this.currentTime = 0;
|
||||||
|
this.play();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.musicPlayerAudio.play();
|
||||||
|
if (fade.fadeIn) {
|
||||||
|
$(this.musicPlayerAudio).prop("volume", 0.0);
|
||||||
|
$(this.musicPlayerAudio).animate({volume: 1.0}, fade.duration * 1000);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log("music: " + name + " " + e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Views.prototype.stopMusic = function (fade) {
|
||||||
|
if (this.musicPlayerAudio.paused) return;
|
||||||
|
|
||||||
|
if (fade.fadeOut) {
|
||||||
|
$(this.musicPlayerAudio).animate({volume: 0.0}, fade.duration * 1000, function() {
|
||||||
|
this.pause();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.musicPlayerAudio.pause();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user