Mercurial > hg > dml-open-cliopatria
annotate cpack/dml/web/js/playlist.js @ 0:718306e29690 tip
commiting public release
author | Daniel Wolff |
---|---|
date | Tue, 09 Feb 2016 21:05:06 +0100 |
parents | |
children |
rev | line source |
---|---|
Daniel@0 | 1 /* Part of DML (Digital Music Laboratory) |
Daniel@0 | 2 Copyright 2014-2015 Samer Abdallah, University College London |
Daniel@0 | 3 Distributed under GPL v3 |
Daniel@0 | 4 */ |
Daniel@0 | 5 |
Daniel@0 | 6 function init_playlist(id){ |
Daniel@0 | 7 var audio=$('#'+id+'-audio'); |
Daniel@0 | 8 var tracks=$('#'+id+'-list').find('li a.audio'); |
Daniel@0 | 9 var current=0; |
Daniel@0 | 10 |
Daniel@0 | 11 console.log('Initialising playlist '+id+' with '+tracks.length+' tracks.'); |
Daniel@0 | 12 last=tracks.length - 1; |
Daniel@0 | 13 audio[0].volume= .50; |
Daniel@0 | 14 tracks.click(function(e){ |
Daniel@0 | 15 e.preventDefault(); |
Daniel@0 | 16 link=$(this); |
Daniel@0 | 17 current=link.parent().parent().index(); |
Daniel@0 | 18 pl_run(link, audio[0]); |
Daniel@0 | 19 }); |
Daniel@0 | 20 audio[0].addEventListener('ended',function(e){ |
Daniel@0 | 21 current++; |
Daniel@0 | 22 if(current==last){current=0; link=tracks[0];} |
Daniel@0 | 23 else{link=tracks[current];} |
Daniel@0 | 24 pl_run($(link),audio[0]); |
Daniel@0 | 25 }); |
Daniel@0 | 26 } |
Daniel@0 | 27 function pl_run(link, player){ |
Daniel@0 | 28 player.src=link.attr('href'); |
Daniel@0 | 29 par=link.parent().parent(); |
Daniel@0 | 30 par.addClass('active').siblings().removeClass('active'); |
Daniel@0 | 31 player.load(); |
Daniel@0 | 32 player.play(); |
Daniel@0 | 33 } |