Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start playing a loaded audio file in the middle with Chrome webkitAudioContext?

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?

like image 385
Karl Ringman Avatar asked Oct 15 '11 23:10

Karl Ringman


People also ask

Can you play a sound on HTML?

The HTML <audio> element is used to play an audio file on a web page.

How to load audio HTML?

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.

How to import audio in JavaScript?

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.


1 Answers

Try the noteGrainOn method of your AudioBufferSourceNode. That method takes an offset and a duration.

like image 143
Matt K Avatar answered Sep 27 '22 16:09

Matt K