Add sounds and stop sound parsing
This commit is contained in:
parent
c1b2e79ca5
commit
c8edde1dfc
@ -335,7 +335,7 @@ Parser.prototype.stop = function() {
|
|||||||
}
|
}
|
||||||
if (this.match(TokenType.SOUND) || this.match(TokenType.SOUNDLOOP)) {
|
if (this.match(TokenType.SOUND) || this.match(TokenType.SOUNDLOOP)) {
|
||||||
var fade = this.matchFade();
|
var fade = this.matchFade();
|
||||||
// ViewActivity.getInstance().stopSound(fade);
|
ViewActivity.getInstance().stopSound(fade);
|
||||||
}
|
}
|
||||||
if (this.match(TokenType.AMBIENCE)) {
|
if (this.match(TokenType.AMBIENCE)) {
|
||||||
var fade = this.matchFade();
|
var fade = this.matchFade();
|
||||||
|
@ -11,6 +11,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.musicQueue = new Array();
|
||||||
|
this.soundQueue = new Array();
|
||||||
|
|
||||||
this.backgroundName = "";
|
this.backgroundName = "";
|
||||||
this.backgroundType = "";
|
this.backgroundType = "";
|
||||||
@ -358,3 +359,38 @@ Views.prototype.stopMusic = function (fade) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Views.prototype.sound = function (name, loop, fade) {
|
||||||
|
try {
|
||||||
|
this.stopSound(this.soundPlayerAudio.fade);
|
||||||
|
this.soundPlayerAudio.src = PathResolver.sound(name);
|
||||||
|
this.soundPlayerAudio.fade = fade;
|
||||||
|
var views = this;
|
||||||
|
this.soundPlayerAudio.addEventListener('ended', function () {
|
||||||
|
if (views.soundQueue.length > 0) {
|
||||||
|
views.sound(views.soundQueue.pop(), false, views.NO_FADE);
|
||||||
|
} else if (loop) {
|
||||||
|
this.currentTime = 0;
|
||||||
|
this.play();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.soundPlayerAudio.play();
|
||||||
|
if (fade.fadeIn) {
|
||||||
|
$(this.soundPlayerAudio).prop("volume", 0.0);
|
||||||
|
$(this.soundPlayerAudio).animate({volume: 1.0}, fade.duration * 1000);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log("sound: " + name + " " + e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Views.prototype.stopSound = function (fade) {
|
||||||
|
if (this.soundPlayerAudio.paused) return;
|
||||||
|
|
||||||
|
if (fade.fadeOut) {
|
||||||
|
$(this.soundPlayerAudio).animate({volume: 0.0}, fade.duration * 1000, function() {
|
||||||
|
this.pause();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.soundPlayerAudio.pause();
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user