Skip to content

Commit

Permalink
enable relaunching the player
Browse files Browse the repository at this point in the history
  • Loading branch information
torbjornbp committed Nov 24, 2024
1 parent c1f3164 commit ff906f2
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions layouts/shortcodes/webamp.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,25 @@
let webampInstance = null;

function launchWebamp() {
if (!webampInstance) {
webampInstance = new Webamp({
initialTracks: {{ $tracks | jsonify | safeJS }}
});

document.getElementById("app").style.display = "block";
webampInstance.renderWhenReady(document.getElementById("app"));
// Always dispose of any existing instance
if (webampInstance) {
webampInstance.dispose();
webampInstance = null;
}

// Create new instance
webampInstance = new Webamp({
initialTracks: {{ $tracks | jsonify | safeJS }}
});

document.getElementById("app").style.display = "block";
webampInstance.renderWhenReady(document.getElementById("app")).then(() => {
// Add an event listener for when Webamp is closed
webampInstance.onClose(() => {
document.getElementById("app").style.display = "none";
webampInstance.dispose();
webampInstance = null;
});
});
}
</script>

0 comments on commit ff906f2

Please sign in to comment.