4 <title>Loop AudioBufferSourceNode, with buffer set after start
</title>
6 var context
= new AudioContext() || new webkitAudioContext();
10 var request
= new XMLHttpRequest();
11 request
.open("GET", "../../LayoutTests/webaudio/resources/media/128kbps-44khz.mp3", true);
12 request
.responseType
= "arraybuffer";
13 request
.onload = function() {
14 context
.decodeAudioData(request
.response
,
17 document
.getElementById("Start").disabled
= false;
18 document
.getElementById("StartDelayed").disabled
= false;
21 alert("Could not load file");
26 function normalStart() {
27 console
.log("normalStart");
28 normalSource
= context
.createBufferSource();
29 normalSource
.loop
= true;
30 normalSource
.buffer
= buffer
;
31 normalSource
.connect(context
.destination
);
32 normalSource
.start(context
.currentTime
+ 2, 0);
34 function delayedStart() {
35 console
.log("delayedStart");
36 delayedSource
= context
.createBufferSource();
37 delayedSource
.loop
= true;
38 delayedSource
.connect(context
.destination
);
39 delayedSource
.start(context
.currentTime
+ 2, 0);
40 setTimeout(function () {
41 delayedSource
.buffer
= buffer
;
48 <h1>Loop AudioBufferSourceNode, with buffer set after start
</h1>
50 <p>Test that looping an AudioBufferSource works correctly if the source is started and the
51 buffer is assigned later, but before the source would start. This can't be easily tested in an
52 offline context because we can't precisely control when the assignment of the buffer to the
55 <p>Press the
"Start" button for the normal case where the buffer is assigned before start.
</p>
57 <p>Press the
"Start delayed" button for the case where the source is started and the buffer
60 <p>You should hear audio about
2 sec after pressing the button. It should continue until you
61 press the corresponding Stop button.
</p>
63 <button id=
"Start" disabled onclick='normalStart()'
>Start
</button>
64 <button id=
"Stop" onclick=
"normalSource.stop()">Stop
</button>
66 <button id=
"StartDelayed" disabled onclick='delayedStart()'
>Start Delayed
</button>
67 <button id=
"StopDelayed" onclick='delayedSource.stop()'
>Stop Delayed Source
</button>