0 votes
asked by (170 points)
How do I, in the current version of Twine 2's Harlowe, check to see if my non-looping audio file has stopped playing? Is there a built-in variable or like that I could do something along the lines of (if: soundHasStopped is "true")..?

 

Basically, for this certain passage the players may be in for a while, I want it to play the first song, then the next, etc. If the above isn't possible, could I somehow create a variable to track this (i.e. set $RoomNameSongCount to $RoomNameSongCount + 1 once the song has finished playing)?

 

I know that I can technically do this just by combining my songs together in one big audio file, but I rather not do that. Thanks in advance!

1 Answer

0 votes
answered by (59.9k points)
selected by
 
Best answer
It depends completely on how you're playing the audio. Are you playing it via the html audio element, the JavaScript web audio API? A JavaScript library?
commented by (170 points)

I am playing it with the HTML audio element. I.e.:

{<audio autoplay loop>
  <source src="C:\TheClickingWell\oral\Qumu2.ogg" type="audio/ogg">
</audio>}

 

commented by (59.9k points)

I would add an id to the element to make is easier to access via code, like: 

<audio id="song" autoplay loop>
...

Then you can grab the track with jQuery like this: 

$('#song')[0]

To check if it's playing: 

(set: _notPlaying to $('#song')[0].paused)

An audio track will always be "paused" if it isn't playing. 

To set up an event for when a track finishes: 

<script>
$("#song").on('ended', function () {
    // JavaScript code
});
</script>

I also suggest taking a look at one of my audio libraries. HTML audio works fine, but Twine's structure often causes problems for audio that's played from within passages. 

https://twinelab.net/harlowe-audio/#/

https://github.com/ChapelR/howler-for-harlowe

The former library is still in beta, but the latter has bugs that won't be fixed. So for right now, you've just got to pick your poison if you want better functionality and control than you can easily get via HTML. Using the former and finding and reporting bugs and issues will help me inprove it though and move it to fill release, but if Howler for Harlowe does everything you need, there's little reason not to use it. 

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...