Hello, I'm brand spanking new to Twine, but I'm a huge fan of computers and an even bigger fan of telling stories.
I'm using the Harlowe story format. I managed to get a sound to loop in the background over all my passages, but it has come to my attention that I need the sound to fade out and then stop for a few passages, and then fade in and loop once more. Help would be appreciated! Thank you!
Comments
eg.
Did you write your own javascript, if so can you show an example of the code?
Did you use a HTML <audio> tag within a passage, if so could you supple an example of the passage.
Did you use another person's javascript script, if so which one?
If you want to keep using Harlowe then the first thing you need to do is change your javascript so that there is some way to find the audio element you created so you can use it later. One way to do this is to give the audio element an ID and to append the element to the body, in the following example I have given the element a ID of nowplaying Now you can use javascript and jQuery to locate the audio element and then either change the music volume or pause it:
note: audio volume ranges from 0.0 (none) to 1.0 (full). The second number in Fade in/out examples is the fade period. Harlowe does not currently have an easy way to call javascript from within a passage, so you have to use a hack. Adding the following to a passage will fade out the music: P.S.
The following javascript encapsulates the above jQuery code convent into a Music namespace, it contains four methods:
1. play(tune); 2. fade(newvolume, period); 3. pause(); 4. stop();
The following script was written in a couple of minutes, it is very rough and contains very little error checking. Add it to your Story Javascript area. To play a tune use the Music.play(tune) method, you can add it to the end of your Story Javascript: To fade in/out (change volume), add something like the following to one of your passages: To pause or stop the music, add something like the following to one of your passages:
I would also change the namespace from Music to Audio to make it more generic.
As in, if I begin playing the music with then stop it with then try to start it again with it gives me an error that "the page's code has got itself in a mess (script error)". It doesn't matter if I'm pausing or stopping the audio.
Is this something to do with the Play function? Or do I only have the option of fading the music in/out?
The Music.play() function in my example expects you to pass it the name of the tune you want it to play, so the call should look something like:
The following is a slightly less rough example of a Sound API which can be used as a starting point. It includes a resume function and the play function has been fixed so that it will not fail when called a second time.
warning: The following still contains very little error checking and has not been fully tested so use at your own risk. The following is an example of the usage of the above rough Sound API, the example assumes that the tune/sound mp3 files are in a media sub-folder: