Short answer: No. You can't change the duration set using the argument.
Long answer:
So start
accepts 3 arguments, when
, offset
, duration
. But all of those are optional. If you don't pass in a duration
argument, it will keep playing till the end of the buffer (or keep looping if you have loop
property set to true
).
So one way to do what you want is to not pass in a duration
argument to start
and then call a stop
function when you want it to stop playing (after 5s). stop
can also be scheduled in advanced using a when
parameter. So in your case it would be calling something like stop(context.currentTime + 3)
at the 2s mark.