I’ve created a global audio element and set the source. I want to use one button to trigger the play/pause functionality (I’d rather not use the timeline for this).
In HeadHTML I’ve got this:
// Add audio
window.audioConv = document.createElement('audio');
Here’s my code for the button toggle:
//find out what scene we are on
var sceneNum = (hypeDocument.currentSceneName()).slice(6);
// Assign the right audio to the scene
audioConv.setAttribute('src', '${resourcesFolderName}/audio' + sceneNum + '.mp3');
//function to toggle play and and pause functionality on button
var buttonText = $(element).html();
if (buttonText == 'Play') {
$(element).html('Pause');
audioConv.play();
} else {
$(element).html('Play');
audioConv.pause();
};
The problem I have is that instead of playing from the currentTime of the audio, it plays from the start every time. If I log currentTime
I find that, indeed, it is 0 and always 0.
How can I fix this?