summaryrefslogtreecommitdiff
path: root/loader.html
blob: 0230da1f90780c1b34452b11160bbdb78d04cbe2 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<html lang="en" dir="ltr">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="buffer-loader.js"></script>
<script type="text/javascript">

window.addEventListener('load', init, false);
var context;
var bufferLoader;

function init() {
	context = new webkitAudioContext();
	$("#info").html("Loading Music Files.....");
	var initial_music_files = [
		'http://www.junglebreaks.co.uk/listen/amen_brother.wav',
		'http://www.junglebreaks.co.uk/listen/apache.wav',
		'http://www.junglebreaks.co.uk/listen/assembly_line.wav',
    ];
	
	for(var i=0; i<initial_music_files.length; i++) {
		var worker = new Worker('loadMusic.js');

		worker.addEventListener('message', function(e) {
			var result = e.data.result;
			if(result == "success") {
				var url = e.data.url;
				var buffer = e.data.response;
				$("#info").html("Loading Completed. Now Playing...");
				$("#files").append("<li>"+url+"</li>");
				
				bufferLoader = new BufferLoader(
					context,
					buffer,
					finishedLoading
				);

				bufferLoader.load();
				
			} else {
				$("#info").html("Cannot load the music file. Please try again with another one...");
			}
		}, false);
		
		worker.postMessage({'cmd': 'load', 'url': initial_music_files[i]});
	}
}

function finishedLoading(bufferList) {
	var source = context.createBufferSource();
	source.buffer = bufferList;
	source.loop = true;
	source.connect(context.destination);
	source.start(0);
}

function LoadNewMusciFile() {
	var url = $("#music_file").val();
	$("#info").html("Loading Music Files.....");
	var worker = new Worker('loadMusic.js');

	worker.addEventListener('message', function(e) {
		var result = e.data.result;
		
		if(result == "success") {
			var url = e.data.url;
			var buffer = e.data.response;
			$("#info").html("Loading Completed. Now Playing...");
			$("#files").append("<li>"+url+"</li>");
			
			bufferLoader = new BufferLoader(
			context,
			buffer,
			finishedLoading
			);

			bufferLoader.load();
			
		} else {
			$("#info").html("Cannot load the music file. Please try again with another one...");
		}
	}, false);

	worker.postMessage({'cmd': 'load', 'url': url});
	
}

</script>
</head>
<body>
<div id="info" style="width:100%;height:30px;padding-bottom:20px;"></div>
<input type="text" name="music_file" id="music_file" style="width:500px;"/>
<input type="button" name="Load" value="Load" onclick="LoadNewMusciFile()">

<div id="files_wrp" style="width:100%;height:auto;padding-top:20px;">
	<div style="width:100%;height:30px;padding-top:20px;font-size:16px; font-weight:bold;">Loaded music file list.</div>
	<ul id="files" style="display:block;"></ul>
</div>

</body>
</html>