Spaces:
Running
Running
Commit ·
9de43a5
1
Parent(s): 26b9060
added MidiAudio.awaitWarmup
Browse files
web/score-player.js
CHANGED
|
@@ -162,6 +162,10 @@
|
|
| 162 |
try {
|
| 163 |
await state.audio.MidiAudio.loadPlugin({ soundfontUrl: SOUNDFONT_URL, api: 'webaudio' });
|
| 164 |
state.audioReady = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
log('audio ready');
|
| 166 |
return true;
|
| 167 |
} catch (e) {
|
|
@@ -203,8 +207,12 @@
|
|
| 203 |
return lo;
|
| 204 |
}
|
| 205 |
|
| 206 |
-
function play () {
|
| 207 |
if (!state.player || !state.midiData || state.isPlaying || state.generating) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
state.isPlaying = true;
|
| 209 |
if (state.pausedTime > 0) {
|
| 210 |
state.playStartTime = performance.now() - state.pausedTime;
|
|
|
|
| 162 |
try {
|
| 163 |
await state.audio.MidiAudio.loadPlugin({ soundfontUrl: SOUNDFONT_URL, api: 'webaudio' });
|
| 164 |
state.audioReady = true;
|
| 165 |
+
// warm up the AudioContext eagerly so later plays are already hot (the
|
| 166 |
+
// in-gesture warmup in play() is what actually satisfies autoplay policy)
|
| 167 |
+
var WA = state.audio.MidiAudio.WebAudio;
|
| 168 |
+
if (WA && WA.awaitWarmup) { try { await WA.awaitWarmup(); } catch (e) {} }
|
| 169 |
log('audio ready');
|
| 170 |
return true;
|
| 171 |
} catch (e) {
|
|
|
|
| 207 |
return lo;
|
| 208 |
}
|
| 209 |
|
| 210 |
+
async function play () {
|
| 211 |
if (!state.player || !state.midiData || state.isPlaying || state.generating) return;
|
| 212 |
+
// warm up the AudioContext (browser autoplay policy) inside the play gesture
|
| 213 |
+
// before scheduling notes, so the opening notes aren't dropped on first play
|
| 214 |
+
var WA = state.audio && state.audio.MidiAudio && state.audio.MidiAudio.WebAudio;
|
| 215 |
+
if (WA && WA.awaitWarmup) { try { await WA.awaitWarmup(); } catch (e) {} }
|
| 216 |
state.isPlaying = true;
|
| 217 |
if (state.pausedTime > 0) {
|
| 218 |
state.playStartTime = performance.now() - state.pausedTime;
|
web/vendor/musicWidgetsBrowser.umd.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dd9c61afba82517fca99babe04ff56f325de55303815d3bc466f26d5125eaee3
|
| 3 |
+
size 44695
|