Skip to content

Instantly share code, notes, and snippets.

@jackpmorgan
Created April 10, 2023 15:43
Show Gist options
  • Save jackpmorgan/98179fa0592a7570f2a57b2d95315c94 to your computer and use it in GitHub Desktop.
Save jackpmorgan/98179fa0592a7570f2a57b2d95315c94 to your computer and use it in GitHub Desktop.
function(instance, properties, context) {
console.log('Updating OME Player');
const HowlerPlayer = window.HowlerPlayer;
if (!instance.data.player) {
console.log('Creating a new player instance');
instance.data.player = new HowlerPlayer(
properties.audiofile,
properties.title,
properties.artistname,
properties.albumname,
properties.imagesrc
);
instance.data.player.audio.volume(properties.volume);
console.log(instance.data.player);
instance.data.audiofile = properties.audiofile;
} else {
var howlerPlayer = instance.data.player;
if (instance.data.audiofile !== properties.audiofile) {
console.log(`OME player instance ID: ${instance.data.playID} audio file has changed`);
instance.data.audiofile = properties.audiofile;
howlerPlayer.audio.stop(instance.data.playID);
howlerPlayer.audio.unload();
instance.data.player = new HowlerPlayer(
properties.audiofile,
properties.title,
properties.artistname,
properties.albumname,
properties.imagesrc
);
howlerPlayer = instance.data.player;
console.log(instance.data.player);
}
howlerPlayer.audio.volume(properties.volume);
}
// Call onSeekUpdate here
howlerPlayer.onSeekUpdate((seekPosition) => {
const minutes = Math.floor(seekPosition / 60);
const seconds = Math.floor(seekPosition % 60).toString().padStart(2, '0');
instance.publishState('seekposition', seekPosition);
instance.publishState('seekpositionstring', `${minutes}:${seconds}`);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment