summaryrefslogtreecommitdiff
path: root/static/sound.js
blob: 85386ce51ac391cb523179b64d6f86e042ebe8b9 (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
function playsound(model) {
	playlist.hintnext();
	var item = model.toJSON();
	var id = item.id;
	var cid = model.cid;
	var el = $('#cid-' + cid);
	el.addClass('loading');
	if(sound) {
		sound.stop();
		sound.destruct();
	}
	sound = soundManager.createSound({
		id: 'audio',
		url: '/track/' + id,
		whileloading: function() {
			$('#status').text('Loading... ' + this.bytesLoaded);
			el.addClass('loading');
		},
		onload: function(success) {
			el.removeClass('loading').removeClass('nocache');
			slider = $('#progress').slider({
				max: sound.duration,
				slide: function(event, ui) {
					if(event.originalEvent && sound)
						sound.setPosition(ui.value);
				}
			});
		},
		whileplaying: function() {
			$('#progress').slider("value", sound.position);
			//$('#' + id).addClass('playing');
			//$('#playlist-' + id).addClass('playing');
			var seconds = (this.position / 1000).toFixed(0);
			var minutes = Math.floor(seconds / 60).toFixed(0);
			seconds %= 60;
			if(seconds < 10)
				seconds = '0' + seconds;
			var pos = minutes + ':' + seconds;
			$('#status').text(pos);
		},
		onstop: function() {
			$('#' + id).removeClass('playing');
		},
		onfinish: function() {
			$('#' + id).removeClass('playing');
			var next = playlist.next();
			if(next) {
				playsound(next, $('#cid-' + next.cid));
			} else {
				sound.stop();
				sound.destruct();
				sound = null;
			}
		}
	});
	sound.play();
	$('#cid-' + cid).addClass('playing');
}

function sound_hint(model) {
	$('#cid-' + model.cid).addClass('loading');
	$.get('/json/hint/' + model.id, function(data) {
		$('#cid-' + model.cid).removeClass('nocache').removeClass('loading');
	});
}