Playing part of a sfx audio file in HTML5 using WebAudio
- by Matthew James Davis
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.