I'm working with the Chrome web audio API and webkitAudioContext to play loops. I have several loops that I'm crossfading in between similar to the Digital DJ example on chromium blog.
In their example they are switching the samples when the loop hits the end of a cycle and then they start playing the next loaded loop. I want to start the new loop instantly and crossfade in between but I have yet to find an example on how to start play a new audio file in the middle and not only from start.
I've looked through the W3C Web Audio API and the noteOn parameter you send in is only a time coded related to the context currentTime attribute when the audio should start playing. It always start playing from the beginning of the sample.
Is there more documentation or something I have overlooked how to start playing an audio file 2seconds in to it?
The HTML <audio> element is used to play an audio file on a web page.
Method 1: Raw HTML The easiest way to load and play a sound file does not actually require any JavaScript at all. HTML includes the <audio></audio> tag, which has a src attribute that you can set to load any sound file you'd like.
We can load an audio file in JavaScript simply by creating an audio object instance, i.e. using new Audio() . After an audio file is loaded, we can play it using the . play() function. In the above code, we load an audio file and then simply play it.
Try the noteGrainOn
method of your AudioBufferSourceNode
. That method takes an offset and a duration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With