+ var player = null;
+ var doesUpdateSynchro = true;
+
+ // TODO: will need class for attach
+ // may be added from sync data
+ $(".syncable").click(function() {
+ if (!$('body').hasClass('with-player-bar')) return;
+ let id = $(this).attr('id');
+ if (!id) return;
+ for (let i=0; i<smil.length; ++i) {
+ if (smil[i][0] == id) {
+ setMediaFromTime(smil[i][1], 'play');
+ //player.jPlayer('play');
+ return;
+ }
+ }
+ });
+
+ var setMediaFromTime = function(time, cmd='pause') {
+ $('.jp-playlist li', $root).each((i, e) => {
+ d = parseFloat($(e).data('duration'));
+ if (time < d) {
+ setMedia($(e), time, cmd);
+ return false
+ } else {
+ time -= d;
+ }
+ })
+ }
+
+ var setMedia = function(elem, time=0, cmd='pause') {
+ var media = {}
+
+ media['mp3'] = elem.attr('data-mp3');
+ media['oga'] = elem.attr('data-ogg');
+ media['id'] = elem.attr('data-media-id');
+
+ $(".c-player__head", $root).html(
+ $(".attribution", elem).html())
+ ;
+ $(".c-player__info", $root).html(
+ $(".title", elem).html()
+ );
+ $(".c-media__caption .content", $root).html($(".project-description", elem).html());
+ $(".c-media__caption .license", $root).html($(".license", elem).html());
+ $(".c-media__caption .project-logo", $root).html($(".project-icon", elem).html());
+
+ console.log('sm 1');
+ doesUpdateSynchro = false;
+ if (!$currentMedia || $currentMedia[0] != elem[0]) {
+ console.log('set', player.jPlayer("setMedia", media))
+ player.jPlayer("option", "playbackRate", speed);
+ }
+ doesUpdateSynchro = true;
+ player.jPlayer(cmd, time);
+
+ $currentMedia = elem;
+ $(".play-next", $root).prop("disabled", !elem.next().length);
+
+ let du = parseFloat(elem.data('duration'));
+ currentDuration = du;
+ elem.nextAll().each(function() {
+ du += parseFloat($(this).data('duration'));
+ });
+ totalDurationLeft = du;
+
+ let pdu = 0;
+ elem.prevAll().each(function() {
+ pdu += parseFloat($(this).data('duration'));
+ });
+ totalDurationBefore = pdu;
+ console.log('sm 3', du, pdu);