Howdy, Stranger!

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

How do you play a sound file in tine 2.x

I have tried a similar format to the method for images:
[audio] src="images/sound.ogg" type="audio/ogg" [/audio]

but this just shows that text.
Does anyone know how to play sound files in 2.0.1?
THanks

Comments

  • It generally helps if you state which story format you are using because the answer can be different for each one but in this case the answer is the same for both Harlowe and Snowman 2.

    These story formats do not have they own built-in way of playing sound so you will need to use one of the standard HTML5 ways of doing it, for example the <audio> HTML tag. Something like the following.

    <audio src="sounds/soundeffect.ogg" autoplay>
    Your browser does not support the <code>audio
    element.

    [quote]I have tried a similar format to the method for images:
    There is currently no built-in way to display images either, so again you have to use standard HTML, the <img> tag in this case:

    <img src="images/smilyface.png" alt="smiley face" height="100" width="100" />
  • Thanks, I got it working with:
    <audio autoplay loop>
    <source src="sound/Space_1.ogg" type="audio/ogg">
    </audio>
    You place the sound files in a folder named sound in your twine 2.0.1 folder, then reference like above. It works like a charm.
  • Is there any way to have this work this with if statements? (like, choosing a different sound depending on a variable)
  • Eingya wrote:

    Is there any way to have this work this with if statements? (like, choosing a different sound depending on a variable)

    You could use (if:) macros to set a variable $sound and then something like the following may work:
    (note: im not at my machine to test atm)

    {
    (set: $sound to "Space_1")

    (print: "<audio autoplay loop><source src=\"sound/" + $sound + ".ogg\" type=\"audio/ogg\"></audio>")
    }
  • If you just want add music to a passage then you can use YouTube:
    Just some text before to see what happens with YouTube link l-dYNttdgl0

    <iframe src="https://youtube.googleapis.com/v/l-dYNttdgl0?autoplay=1&amp;amp;loop=1&amp;amp;playlist=l-dYNttdgl0" style="visibility: hidden; width: 500px; height: 500px; position: absolute; top: -1000px; left: -1000px;"></iframe>

    And some text after the code to see if the page still renders.
    Dump this in a passage for Vivaldi's Spring. I copied the trick from an exported PuzzleScript game.

    Don't know how you'd get it to carry across the whole game though  :-\

    -

    Wait - figured out a tasty hack to call any javascript from Harlowe, so I was able to jQuery this iframe on to the <body> and it stayed when moving passages: http://twinery.org/forum/index.php/topic,2260.msg6635.html#msg6635
  • In Harlowe, I am using the html5 code to play a sound in a passage, but it only plays for 1 second:
    <audio controls autoplay loop>
    <source src="sounds/soundeffect.ogg" type="audio/ogg">
    Your browser does not support the <code>audio
    element.
    Any idea what could be happening? If I play the sound with the controls, I can hear the entire file so it's not that the file is missing or just one second long.

    Thank you!
  • I had this problem, it seems to not like large bits of text.
  • Hi,

    Did you fix the problem? How did you get around it? Do you mean the passage has too much text?

    Thanks,
  • tweller wrote:

    In Harlowe, I am using the html5 code to play a sound in a passage, but it only plays for 1 second:
    <audio controls autoplay loop>
    <source src="sounds/soundeffect.ogg" type="audio/ogg">
    Your browser does not support the <code>audio
    element.
    Any idea what could be happening? If I play the sound with the controls, I can hear the entire file so it's not that the file is missing or just one second long.


    Same here. And the passage where my audio loop starts has only a few words. The loop works when inserted via javascript.
  • This is just the problem I mentioned in the recent post about problems with raw HTML5 audio. If you do an audio-heavy story you need to look into some use of javascript, such as Leon's sound macros at the least.
  • The code worked perfectly for me. (thank you!)
    Is there a way to make it keep playing through despite different passages, like a soundtrack?
    It loops only if I stay on that passage.

  • Yes... notice what @st33d wrote, above:
    Wait - figured out a tasty hack to call any javascript from Harlowe, so I was able to jQuery this iframe on to the <body> and it stayed when moving passages: http://twinery.org/forum/index.php/topic,2260.msg6635.html#msg6635
  • Ok - I can get the sound that @st33d added on Jan 19th, and play music on one passage, but this has me lost:

    http://twinery.org/forum/discussion/2260#msg6635

    How?
Sign In or Register to comment.