Howdy, Stranger!

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

How to play a sound when entering a passage or clicking a link? Twine2 v2.0.10, Harlowe 1.2.1

edited February 2016 in Help! with 2.0
Hello Twine-masters,

although this question is asked quite often I just can't make it work for me. I'm terribly sorry.

I'm using Twine 2.0.10 and the Story Format Harlowe 1.2.1

I just want to have a sound played once when I enter a passage or when I click a link.
I was already trying code that I found in the forum, for example:
<audio src="soundfile.mp3" autoplay>
but I think I'm missing someting because it is just not working.

As an example, here is an excerpt of my passage where I want the sound played when I click on something:
I'm standing in front of a door. 

(link: "Open")[The door is not locked.

<audio src="https://dl.dropboxusercontent.com/u/3267909/___master/twine stuff/Sounds/__Sound of a Murloc.mp3 " autoplay>

[[Go through the door->nextPassage]]
]

1. What do I have to do, to get the sound played when I click on "Open"?
2. And what do I have to do, to get the sound played when I enter a new passage?

I want a lot of small sounds being played in my game. And all of them when I click on something or when I enter a new passage.
With that in mind, can you please tell me an easy way (if possible) how to manage that?

Thank you very much in advance!
Matt

Comments

  • RE: What do I have to do, to get the sound played when I click on "Open"?

    There are a number of issues you will need to overcome:

    1. The syntax of your audio element:
    a. is missing the end </audio> tag
    b. is missing the type information
    <audio src="https://dl.dropboxusercontent.com/u/3267909/___master/twine stuff/Sounds/__Sound of a Murloc.mp3" type="audio/mpeg" autoplay></audio>
    
    2. The installable release of Twine 2 does not support playing media files, so you will need to use the Publish to File option to create a Story HTML file which you acn open using your web-browser if you want to hear the sounds.

    3. The MP3 file you linked to is not cached being pre-cached so once you click the Open link you have to wait for it to download before you will hear anything.

    4. The MP3 file you linked to plays in Firefox, IE, Edge, but not in Chrome.

    RE: get the sound played when I enter a new passage

    Just place the audio element at the start of a passage and it will play, once the sound file has finished downloading.
  • Thank you very much again, greyelf. It is working now.

    I'm not sure if I like, that the sounds always have to be cached first to make them hear.

    Do you know a method how I can make them pre-cached when the story starts maybe? So that they are able to be always played directly when they get clicked?

    In the end I have to give the published Story file to my professor on a CD (she is using a macbook and the safari browser).

    Can I maybe burn the sounds on the CD as well and Twine don't even need to take them from the internet?

    With that in mind, do you have any further advice for me what I maybe have to take in consideration?
  • You could use Javascript to download and pre-cache the audio files into memory, and then use more Javascript to play them but as you are going to supply your Story HTML file on a CD to be played locally you could do as you suggested and burn the sound files on to the CD as well.
    This will result in the audio files playing almost instantly, there is still a slight delay because the file still needs to be loaded into memory.

    If you place your generated Story HTML file and the audio files in the same directory/folder then you will need to change your audio elements to reference the audio files locally like so:
    <audio src="__Sound of a Murloc.mp3" type="audio/mpeg" autoplay></audio>
    

    I don't have Safari installed so you will need to test if each MP3 file works, the web-browser supports MP3 but an individual file may not work if it is faulty in some way.
    This may be the reason that your "__Sound of a Murloc.mp3" file does not work in Chrome.
Sign In or Register to comment.