Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / ManualTests / webaudio / audiobuffersource-loop-grain-no-duration.html
blob8d543a3a88b03c085965ca36789a4ef1175c2a59
1 <!doctype html>
2 <html>
3 <head>
4 <title>Loop AudioBufferSourceNode, with buffer set after start</title>
5 <script>
6 var context = new AudioContext() || new webkitAudioContext();
7 var normalSource;
8 var delayedSource
9 var buffer;
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,
15 function(b) {
16 buffer = b;
17 document.getElementById("Start").disabled = false;
18 document.getElementById("StartDelayed").disabled = false;
20 function () {
21 alert("Could not load file");
22 });
24 request.send();
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;
42 }, 1000);
44 </script>
45 </head>
47 <body>
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
53 source is done.</p>
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
58 assigned later.</p>
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>
65 <br>
66 <button id="StartDelayed" disabled onclick='delayedStart()'>Start Delayed</button>
67 <button id="StopDelayed" onclick='delayedSource.stop()'>Stop Delayed Source</button>
69 </body>
70 </html>