4 $(".jp-jplayer").each(function() {
5 console.log('starting player')
7 var $root = $self.parent();
8 var $currentMedia = null
11 swfPath: "/static/js/contrib/jplayer/",
12 solution: "html,flash",
14 cssSelectorAncestor: "#" + $self.attr("data-player"),
15 useStateClassSkin: true,
21 var setMedia = function(elem, time=0) {
22 console.log('setMedia', elem, time);
25 media['mp3'] = elem.attr('data-mp3');
26 media['oga'] = elem.attr('data-ogg');
27 media['id'] = elem.attr('data-media-id');
29 $(".c-player__head", $root).html(
30 $(".attribution", elem).html())
32 $(".c-player__info", $root).html(
33 $(".title", elem).html()
35 $(".c-media__caption .content", $root).html($(".project-description", elem).html());
36 $(".c-media__caption .license", $root).html($(".license", elem).html());
37 $(".c-media__caption .project-logo", $root).html($(".project-icon", elem).html());
39 player.jPlayer("setMedia", media);
40 player.jPlayer("pause", time);
43 $(".play-prev", $root).prop("disabled", !elem.prev().length);
44 $(".play-next", $root).prop("disabled", !elem.next().length);
49 let selectItem = $('.c-select li');
50 selectItem.on('click', function() {
51 let speed = parseFloat(this.innerHTML);
53 console.log($('audio'));
54 $("audio")[0].playbackRate = speed;
58 $('.play-next', $root).click(function() {
59 let p = $currentMedia.next();
61 setMedia(p).jPlayer("play");
64 $('.play-prev', $root).click(function() {
65 let p = $currentMedia.prev();
67 setMedia(p).jPlayer("play");
71 $('.jp-playlist li', $root).click(function() {
78 var initialElem = $('.jp-playlist li', $root).first();
80 if (true || Modernizr.localstorage) {
82 audiobooks = JSON.parse(localStorage["audiobook-history"]);
86 last = audiobooks[$root.attr("data-book-slug")]
87 // Fallback for book id;
89 last = audiobooks[$root.attr("data-book-id")]
93 initialElem = $('[data-media-id="' + last[1] + '"] .play', $root).first();
94 initialTime = last[2];
95 $number.text($(".jp-playlist .play", $root).index(initialElem) + 1);
98 setMedia(initialElem, initialTime);
101 timeupdate: function(event) {
102 //event.jPlayer.status.currentTime
105 if (true || (event.jPlayer.status.currentTime && Modernizr.localstorage)) {
107 audiobooks = JSON.parse(localStorage["audiobook-history"]);
111 t = event.jPlayer.status.currentTime;
112 if (t && event.jPlayer.status.duration - t > 10) {
113 audiobooks[$root.attr("data-book-slug")] = [
115 event.jPlayer.status.media.id,
116 event.jPlayer.status.currentTime
119 delete audiobooks[$root.attr("data-book-slug")];
121 // Remove old book id, if present.
122 delete audiobooks[$root.attr("data-book-id")];
123 localStorage["audiobook-history"] = JSON.stringify(audiobooks);