audio.play();
$(audio).addClass('playing');
$(this).addClass('playing');
+ $this.fluidbook.sound.pauseAmbient();
} else {
audio.pause();
$(audio).removeClass('playing');
$(this).removeClass('playing');
+ $this.fluidbook.sound.playAmbientIfNothingIsPlaying();
}
return false;
});
},
initTwoStatesIconPlayer: function (player) {
- if ($(player).find('.icon').length>0) {
+ if ($(player).find('.icon').length > 0) {
return;
}
var vp = $(player).next('.visualPlayer');
$(vp).addClass('playing');
}
-
vp.append('<div class="back"></div>');
vp.append('<div class="icon play">' + getSpriteIcon('audioplayer-play') + '</div>');
vp.append('<div class="icon pause">' + getSpriteIcon('audioplayer-pause') + '</div>');
function FluidbookSound(fluidbook) {
this.fluidbook = fluidbook;
+ this.ambientEnabled = false;
+
if (this.fluidbook.settings.soundTheme === 'none' || this.fluidbook.settings.soundTheme == '' || !Modernizr.audio || this.fluidbook.support.iOS || this.fluidbook.support.android) {
this.enabled = false;
this.on = false;
- return;
}
this.enabled = true;
this.volume = 100;
}
this.volume = Math.max(0, Math.min(100, this.volume)) / 100;
- console.log(this.volume, this.fluidbook.settings.soundVolume);
+
+ if (this.fluidbook.settings.ambientSound) {
+ this.ambientEnabled = true;
+ this.ambientVolume = parseFloat(this.fluidbook.settings.ambientSoundVolume);
+ if (isNaN(this.ambientVolume)) {
+ this.ambientVolume = 100;
+ }
+ this.ambientVolume = Math.max(0, Math.min(100, this.ambientVolume)) / 100;
+ this.ambient = new Audio(this.fluidbook.loader.getURL('data/sounds/' + this.fluidbook.settings.ambientSound));
+ this.ambient.volume = 0;
+ this.ambient.loop = true;
+ this.ambient.preload = 'auto';
+ }
this.initEvents();
}
$this.playSoundForPage(data);
});
+ $(this.fluidbook).on('fluidbook.page.change.end', function (e, page, data) {
+ setTimeout(function () {
+ if ($this.isSomethingPlaying()) {
+ $this.pauseAmbient();
+ } else {
+ $this.playAmbientIfNothingIsPlaying();
+ }
+ }, 1000);
+ });
+
$(document).one(this.fluidbook.input.clickEvent, '*', function () {
try {
$this.audios['empty'].play();
$this.playing = $this.audios['empty'];
+ setTimeout(function () {
+ $this.playAmbient();
+ }, 1000);
} catch (e) {
}
return true;
}
},
+ playAmbient: function () {
+ if (!this.ambientEnabled || !this.on) {
+ return;
+ }
+ this.ambient.play();
+ gsap.to(this.ambient, 3, {
+ volume: this.ambientVolume
+ });
+
+ },
+
+ playAmbientIfNothingIsPlaying: function () {
+ if (!this.ambientEnabled || !this.on) {
+ return;
+ }
+ if (!this.isSomethingPlaying()) {
+ return this.playAmbient();
+ }
+ },
+
+ isSomethingPlaying: function () {
+ let $this = this;
+ let res = false;
+ $.each(this.fluidbook.video.getActivePlayers(), function (k, player) {
+ console.log(player);
+ if (player.muted()) {
+ return;
+ }
+ if (player.paused()) {
+ return;
+ }
+ if (player.volume() <= 0) {
+ return;
+ }
+ res = true;
+ return true;
+ });
+ $('audio').each(function () {
+ let a = $(this).get(0);
+ if ($this.isAudioPlaying(a)) {
+ res = true;
+ return true;
+ }
+ });
+ return res;
+ },
+
+ isAudioPlaying: function (a) {
+ return a
+ && a.currentTime > 0
+ && !a.paused
+ && !a.ended
+ && a.readyState > 2;
+ },
+
+ pauseAmbientIfSomethingIsPlaying: function () {
+ if (!this.on || this.isSomethingPlaying()) {
+ this.pauseAmbient();
+ }
+ },
+
+ pauseAmbient: function () {
+ if (!this.ambientEnabled) {
+ return;
+ }
+
+ let $this = this;
+ gsap.to(this.ambient, 1.5, {
+ volume: 0, onComplete: function () {
+ $this.ambient.pause();
+ }
+ });
+ },
+
toggle: function () {
if (this.on) {
this.disable();
enable: function () {
this.on = true;
+ this.playAmbientIfNothingIsPlaying();
$(".icon-sound-off").hide();
$(".icon-sound-on").show();
},
disable: function () {
this.on = false;
+ this.pauseAmbient();
$(".icon-sound-on").hide();
$(".icon-sound-off").show();
},
$.each(hidelinksonplay, function (k, id) {
$this.fluidbook.links.hideLinkById(id);
});
+
+ $this.fluidbook.sound.pauseAmbientIfSomethingIsPlaying();
});
player.on('pause', function () {
$.each(hidelinksonplay, function (k, id) {
$this.fluidbook.links.showLinkById(id);
});
+
+ $this.fluidbook.sound.playAmbientIfNothingIsPlaying();
});
player.on('fullscreenchange', function () {
playersToBeRemoved.forEach(function (player) {
$this.disposeVideo(player);
});
+
+ this.fluidbook.sound.playAmbientIfNothingIsPlaying();
},
disposeVideo: function (player) {