Howdy, Stranger!

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

2 questions about playing sounds

First, I use timedcontinue macro from http://www.glorioustrainwrecks.com/node/5462 and I want to play a sound every time the pause ends. How to modify the script to make it?
Second, I would like to play a local system sound defined by the user's system setting (like "new mail notification") instead of an audio file from the internet. (That is, the user will hear the sound familiar to him in the "new mail" situation. whatever it is on his computer (if it is mute, let it be), and also will be able to play offline.) Is that possible?

Comments

  • You need to state which Story Format you are using when asking a question, as answers can be different for each one.
  • greyelf wrote: »
    You need to state which Story Format you are using when asking a question, as answers can be different for each one.
    Sugarcane. (However, if you have a solution for another format, I can try to adapt it.)

  • If you wish to keep using Sugarcane then I suggest you install the glorioustrainwrecks Twine: HTML5 sound macros to play the sounds.

    You don't need to modify the <<timedcontinue>> macro to do what you want, you could just do the following:
    The text to display before the timedcontinue macro.
    <<timedcontinue "2s">>
    <<playsound "tada.mp3">>
    The text to display after the timedcontinue macro.
    <<endtimedcontinue>>
    

    re: Playing operating system event sound files.
    The web-browser needs to be able to find the sound file you want it to play and I don't know of a way for the web-browser to locate the operating system's sound files. Nor do I know of a way to use Javascript to make the web-browser ask the operating system to trigger the relevant events to play those sounds for you.

    But maybe a more experienced Javascript programmer may know of a solution.
  • greyelf wrote: »
    If you wish to keep using Sugarcane then I suggest you install the glorioustrainwrecks Twine: HTML5 sound macros to play the sounds.
    I know it, but the problem is finding the path to system sounds. As any installer has access to system variables where paths are stored, why javascript cannot? I don't know, however.

    I do need to insert sound playing into <<timedcontinue>> because I will need it in dozens of places! I don't want to add <<playsound "tada.mp3">> after each of them manually!

  • yun wrote: »
    As any installer has access to system variables where paths are stored, why javascript cannot?
    For security reasons, to stop a malicious webpage from accessing system files.
  • I got malicious software many times by visiting a wrong page :( While I don't know if it was written using javascript.
    Anyway, I can give up with system sounds. I have more important problems. I tried <<loopsound>>, and it doesn't stop when I leave the passage. How to fix it?
    Also, I found a place in timedcontinue script where I can insert a call to playsound macro, but what syntax is needed for that? How to call a macro from javascript?
  • edited February 2016
    yun wrote: »
    How to call a macro from javascript?
    Based on the Sugarcane source code I believe it depends on the type of macro you want to call, but generally it would look something like:
    macros["name-of-marco"].handler(element, "name-of-marco", macro_parameters, parser);
    
    element: a reference to the current element being replaced.
    "name-of-marco": is the name of the macro being called. eg. "playsound"
    macro_parameters: an array of parameters to pass to the macro. eg. {"tada.mp3"}
    parser: a RegExp object containing the parse of the current element being replaced
  • yunyun
    edited February 2016
    Well, I just need to execute <<playsound "tada.wav">> (it doesn't play mp3 in Firefox, BTW) within javascript. What "element" should I "replace" and what "parser" do I need?
    macros["playsound"].handler(???, "playsound", "file://C:/WINDOWS/Media/chimes.wav", ???);
    Anyway, this works:
    macros["playsound"].soundtracks["file://C:/WINDOWS/Media/chimes"].play()

    Any ideas how to stop loopsound when leaving the passage? The source code is here: http://www.glorioustrainwrecks.com/files/TwineMacros-SoundMacros-1.1.2.txt
  • yunyun
    edited February 2016
    macros["playsound"].soundtracks["file://C:/WINDOWS/Media/chimes"].play() works only if the same filename is mentioned in the code outside of script section, otherwise "macros.playsound.soundtracks is undefined)"
Sign In or Register to comment.