Separate soundloop from sound
This commit is contained in:
parent
5337b544a9
commit
dff9843c37
@ -298,9 +298,8 @@ Parser.prototype.hide = function() {
|
|||||||
Parser.prototype.play = function() {
|
Parser.prototype.play = function() {
|
||||||
if (this.match(TokenType.MUSIC)) return this.playMusic();
|
if (this.match(TokenType.MUSIC)) return this.playMusic();
|
||||||
if (this.match(TokenType.AMBIENCE)) return this.playAmbience();
|
if (this.match(TokenType.AMBIENCE)) return this.playAmbience();
|
||||||
if (this.lookMatch(0, TokenType.SOUND) || this.lookMatch(0, TokenType.SOUNDLOOP)) {
|
if (this.match(TokenType.SOUND)) return this.playSound();
|
||||||
return this.playSound();
|
if (this.match(TokenType.SOUNDLOOP)) return this.playSoundLoop();
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -312,13 +311,16 @@ Parser.prototype.playMusic = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Parser.prototype.playSound = function() {
|
Parser.prototype.playSound = function() {
|
||||||
var loop = false;
|
|
||||||
if (this.match(TokenType.SOUND)) loop = false;
|
|
||||||
else if (this.match(TokenType.SOUNDLOOP)) loop = true;
|
|
||||||
|
|
||||||
var name = this.consumeMusicName();
|
var name = this.consumeMusicName();
|
||||||
var fade = this.matchFade();
|
var fade = this.matchFade();
|
||||||
ViewActivity.getInstance().sound(name, loop, fade);
|
ViewActivity.getInstance().sound(name, fade);
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
Parser.prototype.playSoundLoop = function() {
|
||||||
|
var name = this.consumeMusicName();
|
||||||
|
var fade = this.matchFade();
|
||||||
|
ViewActivity.getInstance().soundLoop(name, fade);
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -352,10 +354,14 @@ Parser.prototype.stop = function() {
|
|||||||
var fade = this.matchFade();
|
var fade = this.matchFade();
|
||||||
ViewActivity.getInstance().stopMusic(fade);
|
ViewActivity.getInstance().stopMusic(fade);
|
||||||
}
|
}
|
||||||
if (this.match(TokenType.SOUND) || this.match(TokenType.SOUNDLOOP)) {
|
if (this.match(TokenType.SOUND)) {
|
||||||
var fade = this.matchFade();
|
var fade = this.matchFade();
|
||||||
ViewActivity.getInstance().stopSound(fade);
|
ViewActivity.getInstance().stopSound(fade);
|
||||||
}
|
}
|
||||||
|
if (this.match(TokenType.SOUNDLOOP)) {
|
||||||
|
var fade = this.matchFade();
|
||||||
|
ViewActivity.getInstance().stopSoundLoop(fade);
|
||||||
|
}
|
||||||
if (this.match(TokenType.AMBIENCE)) {
|
if (this.match(TokenType.AMBIENCE)) {
|
||||||
var fade = this.matchFade();
|
var fade = this.matchFade();
|
||||||
ViewActivity.getInstance().stopAmbience(fade);
|
ViewActivity.getInstance().stopAmbience(fade);
|
||||||
|
@ -10,6 +10,7 @@ function Views(parser) {
|
|||||||
|
|
||||||
this.musicPlayerAudio = new Audio();
|
this.musicPlayerAudio = new Audio();
|
||||||
this.soundPlayerAudio = new Audio();
|
this.soundPlayerAudio = new Audio();
|
||||||
|
this.soundLoopPlayerAudio = new Audio();
|
||||||
this.ambiencePlayerAudio = new Audio();
|
this.ambiencePlayerAudio = new Audio();
|
||||||
this.musicQueue = new Array();
|
this.musicQueue = new Array();
|
||||||
this.soundQueue = new Array();
|
this.soundQueue = new Array();
|
||||||
@ -370,7 +371,7 @@ Views.prototype.addSoundToQueue = function (name) {
|
|||||||
if (!this.soundPlayerAudio.paused) {
|
if (!this.soundPlayerAudio.paused) {
|
||||||
this.soundQueue.push(name);
|
this.soundQueue.push(name);
|
||||||
} else {
|
} else {
|
||||||
this.sound(name, false, this.NO_FADE);
|
this.sound(name, this.NO_FADE);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -410,7 +411,7 @@ Views.prototype.stopMusic = function (fade) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Views.prototype.sound = function (name, loop, fade) {
|
Views.prototype.sound = function (name, fade) {
|
||||||
try {
|
try {
|
||||||
this.stopSound(this.soundPlayerAudio.fade);
|
this.stopSound(this.soundPlayerAudio.fade);
|
||||||
this.soundPlayerAudio.src = PathResolver.sound(name);
|
this.soundPlayerAudio.src = PathResolver.sound(name);
|
||||||
@ -418,10 +419,7 @@ Views.prototype.sound = function (name, loop, fade) {
|
|||||||
var views = this;
|
var views = this;
|
||||||
this.soundPlayerAudio.addEventListener('ended', function () {
|
this.soundPlayerAudio.addEventListener('ended', function () {
|
||||||
if (views.soundQueue.length > 0) {
|
if (views.soundQueue.length > 0) {
|
||||||
views.sound(views.soundQueue.pop(), false, views.NO_FADE);
|
views.sound(views.soundQueue.pop(), views.NO_FADE);
|
||||||
} else if (loop) {
|
|
||||||
this.currentTime = 0;
|
|
||||||
this.play();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.soundPlayerAudio.play();
|
this.soundPlayerAudio.play();
|
||||||
@ -446,6 +444,38 @@ Views.prototype.stopSound = function (fade) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Views.prototype.soundLoop = function (name, fade) {
|
||||||
|
try {
|
||||||
|
this.stopSoundLoop(this.soundLoopPlayerAudio.fade);
|
||||||
|
this.soundLoopPlayerAudio.src = PathResolver.sound(name);
|
||||||
|
this.soundLoopPlayerAudio.fade = fade;
|
||||||
|
this.soundLoopPlayerAudio.addEventListener('ended', function () {
|
||||||
|
this.currentTime = 0;
|
||||||
|
this.play();
|
||||||
|
});
|
||||||
|
this.soundLoopPlayerAudio.play();
|
||||||
|
if (fade.fadeIn) {
|
||||||
|
$(this.soundLoopPlayerAudio).prop("volume", 0.0);
|
||||||
|
$(this.soundLoopPlayerAudio).animate({volume: 1.0}, fade.duration * 1000);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log("soundloop: " + name + " " + e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Views.prototype.stopSoundLoop = function (fade) {
|
||||||
|
if (this.soundLoopPlayerAudio.paused) return;
|
||||||
|
|
||||||
|
if (fade.fadeOut) {
|
||||||
|
$(this.soundLoopPlayerAudio).animate({volume: 0.0}, fade.duration * 1000, function() {
|
||||||
|
this.pause();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.soundLoopPlayerAudio.pause();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Views.prototype.ambience = function (name, fade) {
|
Views.prototype.ambience = function (name, fade) {
|
||||||
try {
|
try {
|
||||||
this.stopAmbience(this.ambiencePlayerAudio.fade);
|
this.stopAmbience(this.ambiencePlayerAudio.fade);
|
||||||
|
Loading…
Reference in New Issue
Block a user