Adding Sound

Could anyone help me figure out how to embed audio into Squiffy? I don't have experience coding, and the codes I've found thus far have not worked. Any ideas?


Hello!

Welcome to the game!

You can [listen to some music].

[listen to some music]:
<audio src="http://media.textadventures.co.uk/games/1RurGHLuLUqrWdMJh53LTQ/bushcave-explicit-r9/sounds/bushcave.ogg" autoplay />

If you want to display the audio controls for the player, add controls, like this:

<audio src="http://media.textadventures.co.uk/games/1RurGHLuLUqrWdMJh53LTQ/bushcave-explicit-r9/sounds/bushcave.ogg" autoplay controls />

You could also use Javascript:

Version 2

Welcome to the game!

You can [listen to some music].

[listen to some music]:
    ogg = new Audio();
    ogg.src = "http://media.textadventures.co.uk/games/1RurGHLuLUqrWdMJh53LTQ/bushcave-explicit-r9/sounds/bushcave.ogg";
    ogg.load();
    ogg.play();
    set ("ogg",ogg);
You can [[pause the audio]] or [[stop the audio]].

[[pause the audio]]:
    ogg.pause();
You can [[play the audio]] or [[reset the audio]](stop the audio).
    
[[stop the audio]]:
    ogg.pause();
    ogg.currentTime = 0;
You can [[play the audio]].


[[play the audio]]:
    ogg.play();
You can [[pause the audio]] or [[stop the audio]].

You can paste any Squiffy code in here to play around with it:

http://docs.textadventures.co.uk/squiffy/scratchpad/


Thank you that was helpful!

How can I upload my own audio tracks? And is there a way to put the track in a continuous loop, even after using @clear?


To loop without being effected by clearing the screen:

Welcome to the game!

You can [listen to some music].

[listen to some music]:
    ogg = new Audio();
    ogg.src = "http://media.textadventures.co.uk/games/1RurGHLuLUqrWdMJh53LTQ/bushcave-explicit-r9/sounds/bushcave.ogg";
    ogg.load();
    ogg.play();
    ogg.loop = true;
    set ("ogg",ogg);
You can [[clear the screen]], [[pause the audio]] or [[stop the audio]].

[[pause the audio]]:
    ogg.pause();
You can [[play the audio]] or [[reset the audio]](stop the audio).
    
[[stop the audio]]:
    ogg.pause();
    ogg.currentTime = 0;
You can [[play the audio]].


[[play the audio]]:
    ogg.play();
You can [[pause the audio]] or [[stop the audio]].

[[clear the screen]]:
@clear

How can I upload my own audio tracks?

Which version of Squiffy are you using? Windows, Linux/Mac, or Online?


Thanks! I use Mac


Okay...

The most important thing you'll need to know is:

This site has a max upload size of 20 MB.

The second most important thing you'll need to know is:

When using local audio, video, or image files, you have to do all sorts of extra stuff to make sure everything in your games work from within the editor.

Any files you add to your final website's directory will be included, of course, but the path to the file is the screwy part. In order for Squiffy to load a file using a relative path while editing your game, the file needs to be in the same folder as Squiffy itself for the path to be correct once the game is published. So, once you compile your game, you'll need to move some files around.

It's easier to upload the audio files to an online host, then link to that from within the game.


Important note:

If you want your sounds to work in a mobile browser, you must add controls! And autoplay will NOT work in a mobile browser.

[[start]]:
    ogg = new Audio();
    ogg.src = "sndeffect.ogg";
    ogg.load();
    ogg.controls = true;
    ogg.play();
    jQuery("#squiffy-container").append(ogg);
Hello.

Thank you so much! Is there an online host you can recommend for uploading audio files?


Well, I don't practice what I preach.

I use local files. I put them in the directory with Squiffy while editing then move them to the game directory before zipping and submitting.

I think I've heard someone mention SoundCloud, but I'm not sure if I'm on the right track.

Let me go ask the Quest guys what they use. I'll be right back!


Also, you can use onended to run a script once the sound has finished playing:

[[start]]:
    ogg = new Audio();
    ogg.src = "sndeffect.ogg";
    ogg.load();
    ogg.controls = true;
    ogg.play();
    ogg.onended = function(){squiffy.ui.write("The sound has finished!");$(this).remove();}
    jQuery("#squiffy-container").append(ogg);
    set("ogg",ogg);
Hello.

Is there an online host you can recommend for uploading audio files?

I never got any suggestions for this in my post. Sorry... I don't trust any of the free sites I found while doing a quick search, but that's based on nothing. I just don't trust anything "free" on the internet, unless it's open source. I'm sure there are legitimate sites out there, though.

Sorry!


PS

When adding the controls to your audio, clearing the screen will probably remove the audio. (I just thought of that.)


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums