Sounds like you might be starting the running sound by checking is_action_just_pressed, which prevents the sound from starting if the action was already pressed and held before landing. However, as Jgodfrey remarked, such questions are really hard to answer without being able to read the code. Please post the complete script in which the running sound is started/stopped. You can use the curly braces icon above the text box to nicely format code blocks, like this:
My first approach was to use the HTML5 element and define all sound effects in my page. Firefox plays the WAV files just peachy, but calling #play multiple times doesn't really play the sample multiple times. From my understanding of the HTML5 spec, the element also tracks playback state, so that explains why.
So now I can do Snd.boom(); from the Firebug console and play snd/boom.wav, but I still can't play the same sample multiple times. It seems that the element is really more of a streaming feature rather than something to play sound effects with.
I should also mention that, my test environment is Firefox 3.5 on Ubuntu 9.10. The other browsers I've tried - Opera, Midori, Chromium, Epiphany - produced varying results. Some don't play anything, and some throw exceptions.
Although the Audio element is robust enough to be used programmatically for basic tasks, it was never meant to provide full audio support for games and other complex applications. It was designed to allow a single piece of media to be embedded in a page, similar to an img tag. There are a lot of issues with trying to use the it for games:
For game authoring, one of the best solutions is to use a library which solves the many problems we face when writing code for the web, such as howler.js. howler.js abstracts the great (but low-level) Web Audio API into an easy to use framework. It will attempt to fall back to HTML5 Audio Element if Web Audio API is unavailable.
Another library similar to Wad.js is "Sound for Games", it has more focus on effects production, while providing a similar set of functionality through a relatively distinct (and perhaps more concise feeling) API:
Here's one method for making it possible to play even same sound simultaneously. Combine with preloader, and you're all set. This works with Firefox 17.0.1 at least, haven't tested it with anything else yet.
Sounds like what you want is multi-channel sounds. Let's suppose you have 4 channels (like on really old 16-bit games), I haven't got round to playing with the HTML5 audio feature yet, but don't you just need 4 elements, and cycle which is used to play the next sound effect? Have you tried that? What happens? If it works: To play more sounds simultaneously, just add more elements.
I have done this before without the HTML5 element, using a little Flash object from -mp3-player.net/ - I wrote a music quiz ( ) and used it to play clips of music when the user clicked the button for the question. Initially I had one player per question, and it was possible to play them over the top of each other, so I changed it so there was only one player, which I pointed at different music clips.
Here's an idea. Load all of your audio for a certain class of sounds into a single individual audio element where the src data is all of your samples in a contiguous audio file (probably want some silence between so you can catch and cut the samples with a timeout with less risk of bleeding to the next sample). Then, seek to the sample and play it when needed.
If you need more than one of these to play you can create an additional audio element with the same src so that it is cached. Now, you effectively have multiple "tracks". You can utilize groups of tracks with your favorite resource allocation scheme like Round Robin etc.
Have a look at the jai (-> mirror) (javascript audio interface) site. From looking at their source, they appear to be calling play() repeatedly, and they mention that their library might be appropriate for use in HTML5-based games.
I would recommend using SoundJS, a library I've help develop. It allows you to write a single code base that works everywhere, with SoundJS picking web audio, html audio, or flash audio as appropriate.
I ran into this while programming a musicbox card generator. Started with different libraries but everytime there was a glitch somehow. The lag on normal audio implementation was bad, no multiple plays... eventually ended up using lowlag library + soundmanager:
This is certainly not ideal but you could +1 this solution based on creativity alone (and the fact that it is open source and works in any browser that I've tried it on) I hope this gives someone else searching some ideas at least.
You can always try AudioContext it has limited support but it's a part of the web audio api working draft. It might be worth it if you are planing to release something in the future. And if you are only programing for chrome and Firefox you're golden.
Web Audio API is right tool for this job. There is little bit of work involved in loading sounds files and playing it. Luckily there are plenty of libraries out there that simplify the job. Being interested in sounds I also created a library called musquito you can check out that as well.
I have been knocking the rust off my XNA/Monogame skills recently, and have been working on a simple game where I want a bell to sound based on how the player does. For instance, if they strike 3 targets, I want the bell to ring 3 times, or 5 times if they strike 5 targets etc. I hacked together a bit of code that works:
This seems a bit over-complicated to me for such a simple request, but the only other way I could think of to do it was to make an Update() function on my audio manager to run every frame and check a queue of requested sounds for what has played/remains etc. I had wanted to make my audio manager static to function in a kind of fire-and-forget way, so I ended up taking the other approach.
I honestly think this would be a better solution than creating a thread for the sound effects. You could just have the audio manager have one call to audio.Update() in the update loop, and then have a method called PlaySound() which takes the sound you want to play and the number of times you want to play it, and just let audio.Update() handle the implementation. That would still be pretty fire-and-forget.
Dallas Taylor:
Long before Mark worked for Hanna-Barbera, and even before Wile E Coyote was falling off cliffs, Walt Disney made history with Steamboat Willie in 1928. (whistling) This was the first cartoon with synchronized picture and sound. (whistling)
Mark Mangini:
Walt and Roy and Ub Iwerks, themselves, would be the sound effects guy in their live orchestral recording sessions for those early Steamboat Willies. In the early days before there was multi-track recording or mixing, you had to perform the sound effects live with the orchestra in one straight pass. So these sound effects guys had to assemble props, put them in front of microphones, and perform anything that they could acoustically, live, and in sync with the orchestra.
Mark Mangini:
The percussionist would probably have it as part of their kit, and it was just natural to convey going up (slide up) or down (slide down). You could manipulate them in any one of a number of ways, very quickly or very slowly.
Dallas Taylor:
Sound effects played by musical instruments became an iconic part of all cartoons. Then, new audio technology in the 1930s allowed sound editors to add sound effects after recording the orchestra. They could use any prop to make a sound, but often still chose musical instruments.
Mark Mangini:
Once we divorced ourselves from the need to record live to picture, Treg had this fundamental understanding of how to de-contextualize a sound, how to take the sound of your finger in a coke bottle and make that the sound of the Road Runner tongue flip. (coke bottle sound effect)
Dallas Taylor:
Now imagine Tom hanging from his whiskers, and the unavoidable fall as each one is plucked from his cheeks. (plucking sound effect) There were hundreds of familiar sounds like this created at Hanna-Barbera studios.
Dallas Taylor:
In the 1960s, Hanna-Barbera started selling their sound library. Other production companies, like Warner Brothers, use these sounds to this day. The popularity of the Hanna-Barbera sound library has given cartoons an almost universal sound-language. But, Mark feels some sounds are overused.
Mark Mangini:
Which is to say the voices would be assembled in a studio with a script and storyboards. The director of that show would walk the talent through the recording session so that you captured all the voices, speaking all the lines that you needed for that particular episode.
Dallas Taylor:
Since some of the shows she works on are more realistic, Heather wants us to hear the sounds of the characters moving around and interacting with their world. Kinda like a live action movie.
You know the one I'm talking about. A cartoon character is running, and then suddenly they have to stop, so they dig their heels in, lean back, and skid to a stop, accompanied by a rapid-fire series of high-pitched staccato vrt vrt vrt vrt sounds.
Ah, good old foley - the mystic art of inventing sounds to use in creative ways. The practice originated with the old radio serials which were broadcast live, without the benefit of any sort of pre-recording or editing. Around the same time, it was also used to accompany silent films - foley artists would watch the film from behind the screen for cues when to contribute what sound.
Trivia Time: The practice was named for Jack Donovan Foley, who began his career with Universal Studios in 1914. For more than half a century (until his death in 1967), he was THE go-to guy for sound effects in all mediums. Simply called "our Foley" or "Foley artist" at other studios, the position was officially renamed "Foley" in his honor.
Tregoweth Brown of Warner Brothers is credited with introducing the sound in 1931. Dissatisfied with most foley efforts and having access to EVERY sound effect in the studio's library, he commandeered a long panic stop from The Public Enemy, found a fraction of the effect he found particularly appealing, and repeated it several times in rapid succession.
c80f0f1006