Skip preloader warning via settings

master
Will Toohey 9 years ago
parent 368d642bfe
commit 5d9833542e
  1. 5
      src/css/style.css
  2. 27
      src/js/HuesCore.js
  3. 10
      src/js/HuesSettings.js
  4. 56
      src/js/SoundManager.js

@ -159,6 +159,11 @@ h1, h2, h3 {
font-size: 12pt; font-size: 12pt;
} }
#preSub span {
font-size: 8pt;
opacity: 0.7;
}
#tabs { #tabs {
margin: -1px; margin: -1px;
padding-top: 22px; padding-top: 22px;

@ -147,21 +147,36 @@ function HuesCore(defaults) {
this.soundManager = new SoundManager(this); this.soundManager = new SoundManager(this);
this.resourceManager.getSizes(defaults.respacks).then( sizes => { this.soundManager.init().then(() => {
if(!this.soundManager.locked && localStorage["skipPreloader"] == "on") {
return null;
} else {
return this.resourceManager.getSizes(defaults.respacks);
}
}).then( sizes => {
if(sizes === null) {
return;
}
let size = sizes.reduce( (prev, curr) => { let size = sizes.reduce( (prev, curr) => {
return typeof curr === 'number' ? prev + curr : null; return typeof curr === 'number' ? prev + curr : null;
}); }, 0);
if(typeof size === 'number') { if(typeof size === 'number') {
size = size.toFixed(1); size = size.toFixed(1);
} else { } else {
size = '<abbr title="Content-Length header not present for respack URLs">???</abbr>'; size = '<abbr title="Content-Length header not present for respack URLs">???</abbr>';
} }
this.warning(size + "MB of music/images.<br />" + let warning = size + "MB of music/images.<br />" +
"Flashing lights.<br />" + "Flashing lights.<br />" +
"<b>Tap or click to start</b>"); "<b>Tap or click to start</b>";
return this.soundManager.init(); if(!this.soundManager.locked) {
warning += "<br /><span>Skip this screen from Options</span>";
}
this.warning(warning);
// Even if not locked, this steals clicks which is useful here
return this.soundManager.unlock();
}).then(() => { }).then(() => {
this.clearMessage(); this.clearMessage();
setInterval(this.loopCheck.bind(this), 1000); setInterval(this.loopCheck.bind(this), 1000);

@ -67,7 +67,8 @@ HuesSettings.prototype.defaultSettings = {
autoSongShuffle: "on", autoSongShuffle: "on",
autoSongFadeout: "on", autoSongFadeout: "on",
trippyMode: "off", trippyMode: "off",
volume: 0.7 volume: 0.7,
skipPreloader: "off"
}; };
// Don't get saved to localStorage // Don't get saved to localStorage
@ -109,7 +110,8 @@ HuesSettings.prototype.settingsCategories = {
], ],
"Interface" : [ "Interface" : [
"currentUI", "currentUI",
"blackoutUI" "blackoutUI",
"skipPreloader"
] ]
}; };
@ -198,6 +200,10 @@ HuesSettings.prototype.settingsOptions = {
shuffleImages : { shuffleImages : {
name : "Shuffle images", name : "Shuffle images",
options : ["off", "on"] options : ["off", "on"]
},
skipPreloader : {
name : "Skip preloader warning",
options : ["off", "on"]
} }
}; };

@ -29,6 +29,8 @@ function SoundManager(core) {
this.song = null; this.song = null;
this.initPromise = null; this.initPromise = null;
this.lockedPromise = null;
this.locked = true;
/* Lower level audio and timing info */ /* Lower level audio and timing info */
this.context = null; // Audio context, Web Audio API this.context = null; // Audio context, Web Audio API
@ -112,34 +114,42 @@ SoundManager.prototype.init = function() {
audioWorker.postMessage({ping:true, ogg:this.oggSupport}); audioWorker.postMessage({ping:true, ogg:this.oggSupport});
}); });
}).then(() => { }).then(() => {
return new Promise((resolve, reject) => { this.locked = this.context.state != "running";
// iOS and other some mobile browsers - unlock the context as
// it starts in a suspended state
let unlocker = () => {
// create empty buffer
let buffer = this.context.createBuffer(1, 1, 22050);
let source = this.context.createBufferSource();
source.buffer = buffer;
// connect to output (your speakers)
source.connect( this.context.destination);
// play the file
source.start(0);
window.removeEventListener('touchend', unlocker);
window.removeEventListener('click', unlocker);
this.core.clearMessage();
resolve();
};
window.addEventListener('touchend', unlocker, false);
window.addEventListener('click', unlocker, false);
});
}); });
} }
return this.initPromise; return this.initPromise;
}; };
SoundManager.prototype.unlock = function() {
if(this.lockedPromise) {
return this.lockedPromise;
}
this.lockedPromise = new Promise((resolve, reject) => {
// iOS and other some mobile browsers - unlock the context as
// it starts in a suspended state
let unlocker = () => {
// create empty buffer
let buffer = this.context.createBuffer(1, 1, 22050);
let source = this.context.createBufferSource();
source.buffer = buffer;
// connect to output (your speakers)
source.connect( this.context.destination);
// play the file
source.start(0);
window.removeEventListener('touchend', unlocker);
window.removeEventListener('click', unlocker);
this.core.clearMessage();
resolve();
};
window.addEventListener('touchend', unlocker, false);
window.addEventListener('click', unlocker, false);
});
return this.lockedPromise;
}
SoundManager.prototype.playSong = function(song, playBuild, forcePlay) { SoundManager.prototype.playSong = function(song, playBuild, forcePlay) {
let p = Promise.resolve(); let p = Promise.resolve();
// Editor forces play on audio updates // Editor forces play on audio updates

Loading…
Cancel
Save