Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Inline HTML5 audio element gets paused a moment after loading (Harlowe+Twine2)

I was experimenting with adding audio using Twine 2 and the Harlowe 1.1 Beta.  I believe this issue was present in earlier versions, though, since I found this post from January with the same problem:
http://twinery.org/forum/index.php/topic,2270.msg6682.html#msg6682

Good news is that since Harlowe 1.1 supports executing <script> tags, you can just include this in a particular passage and it works fine:

<script>
var audio = document.createElement('audio');
audio.src = 'audio.mp3';
audio.type = 'audio/mpeg';
audio.loop = true;
audio.play();
</script>
But I thought I'd post the results of my investigation anyways in case it is relevant to someone.  Inserting the audio element inline as follows, the problem is observed where the audio loads fine and plays for a second before pausing for no apparent reason:

<audio id="myVideo" autoplay controls>
<source src="audio.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>

<script>
$('audio').on("abort canplay canplaythrough durationchange emptied ended error loadeddata loadedmetadata loadstart pause play playing progress ratechange seeked seeking stalled suspend timeupdate volumechange waiting",function(e){
console.log(e.type);
});
</script>
The additional script code logs every event on the audio element.  Console output looks like this after loading:

VM118:50 Loaded the built-in macros.
VM122:2 loadstart
VM122:2 durationchange
VM122:2 loadedmetadata
VM122:2 progress
VM122:2 suspend
VM122:2 loadeddata
VM122:2 canplay
VM122:2 play
VM122:2 playing
VM122:2 canplaythrough
3 VM122:2 timeupdate
VM122:2 pause
That last pause event happens on its own.  I'm not sure what could be causing it.  I'd have just submitted a bug to Harlowe repository, but I don't see a way of doing so on bitbucket (https://bitbucket.org/_L_/harlowe)
Sign In or Register to comment.