diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2012-03-05 22:44:58 +0100 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2012-03-05 22:44:58 +0100 |
commit | 5a0d0b7fa043678d09409e3b0a7a9d541b65663f (patch) | |
tree | 1c6c9e633fc1866ac05578bc08d2845f3c40a230 /static/sound.js | |
parent | 39e3b4c0822780310af8dd9b0f9dd89225be3b5c (diff) |
Added basic playlist implementation using backbone.js.
Diffstat (limited to 'static/sound.js')
-rw-r--r-- | static/sound.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/static/sound.js b/static/sound.js new file mode 100644 index 0000000..252741c --- /dev/null +++ b/static/sound.js @@ -0,0 +1,53 @@ +function playsound(model) { + 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/' + item.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.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)); + } + } + }); + sound.play(); + $('#cid-' + cid).addClass('playing'); +} |