Playing part of a sfx audio file in HTML5 using WebAudio

Posted by Matthew James Davis on Game Development See other posts from Game Development or by Matthew James Davis
Published on 2013-06-22T22:52:22Z Indexed on 2013/06/24 16:39 UTC
Read the original article Hit count: 258

Filed under:
|
|

I have compiled all of my sound effects into one sequenced .ogg file. I have the start and stop times for each sound effect. How do I play the individual effects? That is, how do I play part of an audio file.

More specificially, I've created a dictionary

{
    'sword_hit':
    {
        src: 'sfx.ogg',
        start: 265, // ms
        length: 212 // ms
    }
}

that my play_sound() function can use to look up 'sword_hit' and play the correct audio file at the correct start time for the correct duration. I simply need to know how to tell the WebAudio API to start playing at start ms and only play for length ms.

© Game Development or respective owner

Related posts about html5

Related posts about audio