HAL; The problem of whether or not a sound is heard

Twine Version: Harlowe 3.2.3

The passage code that should make a sound is like this:

{<audio id="doorOpen" src="https://example1.mp3"></audio>
<br>
<br>
(link: "1")[
        (track: 'doorOpen', 'play')
    (goto: "1")
]
<br>
(link: "2")[
        (track: 'doorOpen', 'play')
    (goto: "2")
]
<br>
(link: "3")[
        (track: 'doorOpen', 'play')
    (goto: "3")
]
}

This is the code for hal.tracksd and of course, when testing it, I use a real mp3 link.

doorOpen: https://example1.mp3
drawerOpen: https://example2.mp3
OUTdoorOpen: https://example3.mp3

The problems I’m having are:

1. When going from a higher level to a lower level, only one of the three sounds plays.

2. When I click on a link I’ve already clicked, the sound doesn’t play.

3. When I go to a lower level and then return to the higher level, the sound doesn’t play.

Strangely, if I start playing from the level where the sound should play, it works fine. Otherwise, either no sound at all or only one of the three identical sounds plays. How can I fix this?

You shouldn’t mix HTML element based audio with Harlowe Audio Library (HAL) based audio, because the two different methods aren’t aware of each other, nor can the HAL macros control what the HTML element is doing.
eg. Using a HAL macro call like the following…

(track: 'doorOpen', 'play')

…will have no affect on this element…

<audio id="doorOpen" src="https://example1.mp3"></audio>

note: the correct link family macro to use, when wanting to execute some code before transition to a Passage, is (link-reveal-goto:)

(link-reveal-goto: '1', '1')[
    (track: 'doorOpen', 'play')
]

When going from a higher level to a lower level, only one of the three sounds plays.

The (track:) macro called by all three links has the same ‘doorOpen’ track identifier, so they all will play that track. If you want one of those links to play the drawerOpen track, and another to play the OUTdoorOpen track, then you need to pass those identifiers to the relevant (track:) macro call.
eg.

(link-reveal-goto: '1', '1')[
    (track: 'doorOpen', 'play')
]

(link-reveal-goto: '2', '2')[
    (track: 'drawerOpen', 'play')
]

(link-reveal-goto: '3', '3')[
    (track: 'OUTdoorOpen', 'play')
]

There are a number of reasons why a audio track won’t play, some of then are:

  • the URL associated with the track identifier isn’t referencing an actual audio file. Many file hosting sites return a web-page instead of the actual audio file, and HAL doesn’t support that behaviour.
  • the audio file itself is unplayable. This can be checks by copying the URL into a blank tab of the web-browser, and seeing if it plays.
  • the end-user hasn’t interacted with the page yet, which is required by the security system of most web-browsers before they will let audio auto-play.

Because you have supplied fake URLs we have no way of testing your code against the tracks you are trying to play.

1 Like

The problem I was having wasn’t with HAL, but with a complexly convoluted passage structure. That’s why the sound wouldn’t play. I’ve fixed it now.
Thank you for teaching me the correct macro (link-reveal-goto:) to use before switching passages. Previously, there was a delay before the sound would play for the first time, but after applying this code, there was no delay. I’ve applied it to my story.

To elaborate on the insufficient explanation in my question, my goal was to play the same sound in the same passage, since I was opening the top drawer, the middle drawer, and the bottom drawer on one page. In the lower passages, I was also aiming to play three identical sounds, such as opening doors in different rooms.

I remember you were the only one who answered my first Twine Harlowe question about three years ago. I’ve since lost that account, but you’re still active. Thank you for your kind response :slight_smile:

1 Like