Does HTML5 exporting do something to the .play function in Javascript?

Jan 03, 2018

Hi everyone!

I know that messing around with the exported .html files from Storyline isn't officially supported, but I wondered if anyone could help with this issue. I've made a Javascript track changer for background music on this project, pasted the script into the story.html file, and put the audio file in the same folder. This works perfectly fine and as intended, however when I do the same for story_html5.html, Javascript gives an error saying "Uncaught TypeError: track1.play is not a function".

I'm far from an expert on Javascript, but I've tried a few changes and the error always seems to be with the .play function.

This is the script that it's catching on:

var track1 = new Audio('Track1.mp3');

track1.play();

 

9 Replies
Sarah C

Interesting, I wonder why it's doing that here and not in non-HTML5 exports? I thought Audio was supposed to be taken from the HTML audio object so it might not necessarily have to construct itself there. I've tried to think of a way to control this more from the HTML side but I'm confusing myself a bit. The setup I'm working with has three buttons that control three different background music tracks:

//Track listings

var track1 = new Audio('Track1.mp3');
var track2 = new Audio('Track2.mp3');
var track3 = new Audio('Track3.mp3');

//Autoplay first track

track1.play();

//Toggle the first track between play and pause, change the button CSS to reflect which

function playTrack1() {
if (track1.paused) {
track2.pause();
track3.pause();
track1.play();
pButton1.className = "play";
pButton2.className = "pause";
pButton3.className = "pause";
} else {
track1.pause();
pButton1.className = "pause";
}
}

Then I've just repeated the toggle code twice more for the other tracks/buttons. I wonder if the HTML5 export might be somehow overriding the Audio object somewhere?

If I've completely misunderstood you, apologies! I'm not very knowledgable on the coding/web development side of things. Thanks for your help.

EDIT: Yes, the issue is with the native Audio Javascript being overwritten somewhere. Using an alert on Audio makes it come up with a different function than it would on a vanilla page. So my followup question would be, is there a way to make this work knowing that, or is there no other way I can play audio here?

chiefy .

I came across a similar issue when trying to mute all the audio on a slide. If I remember correctly, it is to do with how Storyline creates the audio for the Flash vs HTML5 output. The Flash version uses a html <audio> element, while the HTML5 version does not.

To fix this unusual inconsistency between outputs I had to edit player.js to make the audio output consistent. I can't remember exactly what I had to change, so I can't help you there.

I'm sure that the Staff will be able to help you with this.

Sarah C

Aha, thank you! You're right, it's in mobile/player_compiled.js at the end of line 618. Deleting that part (naturally) broke the player, but it did return function to my audio buttons. Unfortunately I've got no idea what I'm dealing with within this script, but at least we're getting closer!

Edit: It seems to only break the player if there's sound on the slides, which I suppose makes sense. 

Sarah C

No problem at all! I ran it through that (should have done that in the first place), but I only come up with 28 347 lines total. I'm also using player_compiled.js as I don't seem to have a player.js.

I've found quite a few lines that contain "loadAudioFromXML", which seemed to be the problem in your other thread. Is that familiar as the section that needed replacing? I know you said that you don't quite remember what was supposed to be replaced, so no worries if you're not sure. Thanks for taking the time to help me out!

This discussion is closed. You can start a new discussion or contact Articulate Support.