Musik lückenlos abspielen & Cookie-Hinweis rescaling angepasst
This commit is contained in:
@@ -119,6 +119,7 @@ class SoundManager {
|
||||
|
||||
constructor() {
|
||||
this.channels = {};
|
||||
this.context = new AudioContext();
|
||||
}
|
||||
|
||||
set(options, channel) {
|
||||
@@ -131,49 +132,24 @@ class SoundManager {
|
||||
|
||||
let audio = options.audio;
|
||||
if (Helper.isNotNull(audio)) {
|
||||
let src = null;
|
||||
if (typeof audio === "string") {
|
||||
src = audio;
|
||||
audio = new Audio();
|
||||
audioObject.loadedPromise = new Promise((resolve, reject) => {
|
||||
audio.addEventListener("loadeddata", () => {
|
||||
resolve();
|
||||
});
|
||||
audio.addEventListener("error", (e) => {
|
||||
console.warn(e);
|
||||
reject(e);
|
||||
});
|
||||
});
|
||||
audio.src = Helper.basePath(src);
|
||||
}
|
||||
else {
|
||||
audioObject.loadedPromise = Promise.resolve();
|
||||
}
|
||||
audioObject.loadedPromise = fetch(audio).then(res => res.arrayBuffer()).then(arrayBuffer => this.context.decodeAudioData(arrayBuffer));
|
||||
this.stop(channel);
|
||||
audioObject.audio = audio;
|
||||
// audio.addEventListener('timeupdate', () => {
|
||||
// let buffer = 10;
|
||||
// if (this.channels[channel].audio === audio && this.channels[channel].loop) {
|
||||
// if (audio.currentTime > audio.duration - buffer) {
|
||||
// console.log("reset");
|
||||
// audio.currentTime = 0;
|
||||
// audio.play();
|
||||
// }
|
||||
// }
|
||||
// }, false);
|
||||
}
|
||||
audioObject.muted = Helper.nonNull(options.muted, audioObject.muted, false);
|
||||
audioObject.volume = Helper.nonNull(options.volume, audioObject.volume, 1);
|
||||
audioObject.loop = Helper.nonNull(options.loop, audioObject.loop, false);
|
||||
audioObject.timeOffset = Helper.nonNull(options.timeOffset, audioObject.timeOffset, 0);
|
||||
|
||||
if (audioObject.muted){
|
||||
this.stop(channel);
|
||||
}
|
||||
|
||||
this.channels[channel] = audioObject;
|
||||
this._update(channel);
|
||||
|
||||
return this.channels[channel];
|
||||
}
|
||||
|
||||
play(channel, audioOrOptions) {
|
||||
async play(channel, audioOrOptions) {
|
||||
channel = Helper.nonNull(channel, SoundManager.CHANNELS.DEFAULT);
|
||||
if (Helper.isNull(audioOrOptions)) {
|
||||
audioOrOptions = {};
|
||||
@@ -186,10 +162,17 @@ class SoundManager {
|
||||
|
||||
this.stop(channel);
|
||||
this.set(audioOrOptions, channel);
|
||||
// this._update(channel);
|
||||
|
||||
if (!this.channels[channel].muted) {
|
||||
this.channels[channel].audio.play();
|
||||
let buffer = await this.channels[channel].loadedPromise;
|
||||
let source = this.context.createBufferSource();
|
||||
source.buffer = buffer;
|
||||
source.connect(this.context.destination);
|
||||
// source.loopStart = 5;
|
||||
// source.loopEnd = 5;
|
||||
source.loop = this.channels[channel].loop;
|
||||
source.start(0);
|
||||
this.channels[channel].source = source;
|
||||
}
|
||||
return this.channels[channel];
|
||||
}
|
||||
@@ -198,22 +181,10 @@ class SoundManager {
|
||||
channel = Helper.nonNull(channel, SoundManager.CHANNELS.DEFAULT);
|
||||
|
||||
let oldAudio = this.channels[channel];
|
||||
if (oldAudio != null) {
|
||||
oldAudio.audio.pause();
|
||||
if (Helper.nonNull(oldAudio) && Helper.nonNull(oldAudio.source)) {
|
||||
oldAudio.source.stop();
|
||||
}
|
||||
}
|
||||
|
||||
_update(channel) {
|
||||
let audioObject = this.channels[channel];
|
||||
|
||||
audioObject.audio.currentTime = Helper.nonNull(audioObject.timeOffset, audioObject.audio.currentTime);
|
||||
audioObject.audio.loop = Helper.nonNull(audioObject.loop, audioObject.audio.loop);
|
||||
audioObject.audio.volume = Helper.nonNull(audioObject.volume, audioObject.audio.volume);
|
||||
if (audioObject.muted) {
|
||||
this.stop(channel);
|
||||
}
|
||||
}
|
||||
|
||||
get(channel) {
|
||||
channel = Helper.nonNull(channel, SoundManager.CHANNELS.DEFAULT);
|
||||
return this.channels[channel];
|
||||
|
||||
@@ -1373,6 +1373,12 @@ ThemeManager.themes = [];
|
||||
ThemeManager.changeListeners = [];
|
||||
|
||||
class CookieCompliance {
|
||||
|
||||
static async showIfNeeded(cookieContainer) {
|
||||
let cookieCompliance = new CookieCompliance(cookieContainer);
|
||||
return cookieCompliance.showIfNeeded();
|
||||
}
|
||||
|
||||
constructor(cookieContainerId) {
|
||||
this.cookieContainerId = cookieContainerId;
|
||||
this.dropCookie = true;
|
||||
@@ -1381,11 +1387,11 @@ class CookieCompliance {
|
||||
this.cookieValue = 'true';
|
||||
}
|
||||
|
||||
showIfNeeded()
|
||||
{
|
||||
async showIfNeeded() {
|
||||
if (CookieCompliance.checkCookie(this.cookieName) !== this.cookieValue) {
|
||||
this.show();
|
||||
return this.show();
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
removeMe() {
|
||||
@@ -1429,12 +1435,14 @@ class CookieCompliance {
|
||||
show() {
|
||||
let cookieCompliance = this;
|
||||
const cookieMessage = document.getElementById(this.cookieContainerId);
|
||||
cookieMessage.style.display='block';
|
||||
cookieMessage.querySelector("#close-cookie-msg").onclick = function(){
|
||||
cookieCompliance.removeMe();
|
||||
cookieMessage.remove();
|
||||
};
|
||||
|
||||
cookieMessage.style.display = 'block';
|
||||
return new Promise(r => {
|
||||
cookieMessage.querySelector("#close-cookie-msg").onclick = function () {
|
||||
cookieCompliance.removeMe();
|
||||
cookieMessage.remove();
|
||||
r();
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2343,7 +2351,7 @@ class App {
|
||||
|
||||
if (this._showCookieCompliance)
|
||||
{
|
||||
new CookieCompliance('cookie-compliance').showIfNeeded();
|
||||
this._cookieClosePromise = CookieCompliance.showIfNeeded('cookie-compliance');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user