Does HTML5 exporting do something to the .play function in Javascript?
Jan 03, 2018
By
Sarah C
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
Add a line just before the track1.play() that alerts the track1 variable and you'll see the track1 object is null. Root cause is inside the code running as the Audio class is constructing itself in the first line of source you posted.
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:
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?
For reference, this is what it's coming up with:
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.
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, I've found the only thread I made on this topic. Hopefully it can be of some help to you.
https://community.articulate.com/discussions/articulate-storyline/audio-elements-missing-from-index_lms_html5
Brilliant! Thank you very much. One question about your fix though, you mentioned replacing the function on line 29,238 with some other code. Which file was that in? I can't find anything with more than around 2000 lines in my exported files.
Hi Sarah, sorry for taking a while to get back to you. This is in player.js, you need to beautify the file at a website such as this http://jsbeautifier.org/
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.