This repository has been archived by the owner on Jan 7, 2019. It is now read-only.
/
index.html
57 lines (45 loc) · 1.59 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html lang="en" manifest="web.appcache">
<head>
<meta charset="utf-8" />
<title>Offline Audio Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="Alex Gibson" />
<script src="sounds/ufo.js"></script>
<script src="js/base64-binary.js"></script>
<script type="text/javascript">
var myAudioContext, mySource, myBuffer;
if ('AudioContext' in window) {
myAudioContext = new AudioContext();
} else if ('webkitAudioContext' in window) {
myAudioContext = new webkitAudioContext();
} else {
alert('Your browser does not support yet Web Audio API');
}
function play () {
mySource = myAudioContext.createBufferSource();
mySource.buffer = myBuffer;
mySource.connect(myAudioContext.destination);
if ('AudioContext' in window) {
mySource.start(0);
} else if ('webkitAudioContext' in window) {
mySource.noteOn(0);
}
}
var load = (function (url) {
var arrayBuff = Base64Binary.decodeArrayBuffer(sound);
myAudioContext.decodeAudioData(arrayBuff, function(audioData) {
myBuffer = audioData;
});
}());
</script>
</head>
<body>
<h1>Offline Web Audio Demo</h1>
<p>The sound in this demo is stored as a base64 string and converted back to audio data for playback via the Web Audio API. This enables mobile browsers such as iOS6 Safari to cache audio offline for playback.</p>
<p>Press play below:</p>
<button onClick="play();" style="height: 44px; width: 75px;">Play</button>
<p>Fork on <a href="https://github.com/alexgibson/offlinewebaudio">GitHub</a></p>
<p>Demo by: <a href="http://alxgbsn.co.uk">Alex Gibson</a></p>
</body>
</html>