Skip to content

Instantly share code, notes, and snippets.

@hogart
Last active October 15, 2019 14:45
Show Gist options
  • Save hogart/dab4c1c5c29c2056353d400f92e2498b to your computer and use it in GitHub Desktop.
Save hogart/dab4c1c5c29c2056353d400f92e2498b to your computer and use it in GitHub Desktop.
twine-bgmusic
::StoryTitle
twine-bgmusic
::PassageReady
<<if !$masterPlaying && passage() !== 'YOUR-START-PASSAGE'>>
<<bgsound>>
<</if>>
::_setup-sound
<!-- <<include [[_setup-sound]]>> in StoryInit -->
<<set $trackStartCrossfade = 15>>
<<set $masterPlaying = false>>
<<set $audioEnabled = window.location.host.includes('ssl.hwcdn.net') || window.hasMusic || window.location.host.includes('localhost')>>
<<if $audioEnabled>>
<<waitforaudio>>
<<cachetrack "YOUR-TRACK">>
<<waitforaudio>>
<</if>>
::widget-bgsound [widget]
<<widget bgsound>>
<<if $audioEnabled>>
<<set _track = ($args[0] || 'YOUR-TRACK')>>
<<audio _track volume 0 fadeoverto $trackStartCrossfade 1 loop>>
<<set $masterPlaying = true>>
<</if>>
<</widget>>
::widget-cachetrack [widget]
<<widget "cachetrack">>
<!-- trackname, [path = './sound/'] -->
<<set _path = ($args[1] || './sound/') + $args[0] + '.'>>
<<cacheaudio $args[0] `_path + 'mp3'` `_path + 'ogg'`>>
<</widget>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment