|
@@ -35,11 +35,14 @@ async function init() { |
|
|
e => eventEmitter.emit("mastervolumechange", e.target.value) |
|
|
e => eventEmitter.emit("mastervolumechange", e.target.value) |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// Load the file |
|
|
|
|
|
await playlist.load([{ |
|
|
|
|
|
src: document.URL, |
|
|
|
|
|
}]); |
|
|
|
|
|
|
|
|
// Read target fragment from URL |
|
|
|
|
|
let start, end; |
|
|
|
|
|
|
|
|
|
|
|
async function setFragmentToSelection() { |
|
|
|
|
|
|
|
|
function syncFragmentToSelection() { |
|
|
|
|
|
// Read target fragment from URL |
|
|
|
|
|
let start, end; |
|
|
|
|
|
|
|
|
const fragmentIdentifier = window.location.hash; |
|
|
const fragmentIdentifier = window.location.hash; |
|
|
if (fragmentIdentifier) { |
|
|
if (fragmentIdentifier) { |
|
@@ -56,30 +59,22 @@ async function init() { |
|
|
|
|
|
|
|
|
// Emit event to update selection in player |
|
|
// Emit event to update selection in player |
|
|
eventEmitter.emit('select', start, end); |
|
|
eventEmitter.emit('select', start, end); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Bind window hash change to update player |
|
|
// Bind window hash change to update player |
|
|
window.addEventListener('hashchange', async function() { |
|
|
|
|
|
|
|
|
window.addEventListener('hashchange', async function() { |
|
|
if(playlist.isPlaying()) { |
|
|
if(playlist.isPlaying()) { |
|
|
eventEmitter.emit('stop') |
|
|
eventEmitter.emit('stop') |
|
|
// pause needs a small delay, coz the lib doesn't |
|
|
// pause needs a small delay, coz the lib doesn't |
|
|
// update player view (drawRequest) when isPlaying() = true. |
|
|
// update player view (drawRequest) when isPlaying() = true. |
|
|
await delay(10); |
|
|
await delay(10); |
|
|
} |
|
|
} |
|
|
await setFragmentToSelection(); |
|
|
|
|
|
eventEmitter.emit('play'); |
|
|
|
|
|
|
|
|
await syncFragmentToSelection(); |
|
|
|
|
|
eventEmitter.emit('play'); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Load Playlist |
|
|
|
|
|
await playlist.load([{ |
|
|
|
|
|
src: document.URL |
|
|
|
|
|
}]); |
|
|
|
|
|
|
|
|
|
|
|
// update start & end for initial load |
|
|
|
|
|
setFragmentToSelection(); |
|
|
|
|
|
|
|
|
// Read start & end from window location. |
|
|
|
|
|
syncFragmentToSelection(); |
|
|
|
|
|
|
|
|
// Start playing. A tiny delay seems needed in Firefox to show the cursor at the right place. |
|
|
// Start playing. A tiny delay seems needed in Firefox to show the cursor at the right place. |
|
|
requestAnimationFrame(() => eventEmitter.emit('play')); |
|
|
requestAnimationFrame(() => eventEmitter.emit('play')); |
|
|