4 $.jPlayer.timeFormat.showHour = true;
6 $(".jp-jplayer").each(function() {
8 var $root = $self.parent();
9 var $currentMedia = null
10 var currentDuration = 0;
12 var totalDurationLeft = 0;
16 var setMedia = function(elem, time=0) {
19 media['mp3'] = elem.attr('data-mp3');
20 media['oga'] = elem.attr('data-ogg');
21 media['id'] = elem.attr('data-media-id');
23 $(".c-player__head", $root).html(
24 $(".attribution", elem).html())
26 $(".c-player__info", $root).html(
27 $(".title", elem).html()
29 $(".c-media__caption .content", $root).html($(".project-description", elem).html());
30 $(".c-media__caption .license", $root).html($(".license", elem).html());
31 $(".c-media__caption .project-logo", $root).html($(".project-icon", elem).html());
33 player.jPlayer("setMedia", media);
34 player.jPlayer("option", "playbackRate", speed);
35 player.jPlayer("pause", time);
38 $(".play-next", $root).prop("disabled", !elem.next().length);
40 let du = elem.data('duration');
42 elem.nextAll().each(function() {
43 du += $(this).data('duration');
45 totalDurationLeft = du;
52 swfPath: "/static/js/contrib/jplayer/",
53 solution: "html,flash",
55 cssSelectorAncestor: "#" + $self.attr("data-player"),
56 useStateClassSkin: true,
61 let selectItem = $('.c-select li');
62 selectItem.on('click', function() {
63 let speedStr = $(this).data('speed');
64 speed = parseFloat(speedStr);
65 player.jPlayer("option", "playbackRate", speed);
66 localStorage['audiobook-speed'] = speedStr;
69 $('.play-next', $root).click(function() {
70 let p = $currentMedia.next();
72 setMedia(p).jPlayer("play");
75 $('.play-prev', $root).click(function() {
76 let p = $currentMedia.prev();
78 setMedia(p).jPlayer("play");
80 // If in first part, restart it.
81 setMedia($currentMedia).jPlayer("play");
85 $('.jp-playlist li', $root).click(function() {
86 setMedia($(this)).jPlayer("play");
87 $('.c-player__chapters').removeClass('is-active');
90 var initialElem = $('.jp-playlist li', $root).first();
92 if (true || Modernizr.localstorage) {
94 let speedStr = localStorage['audiobook-speed'];
96 speed = parseFloat(speedStr);
97 $(".speed .is-active").removeClass("is-active");
98 $(".speed [data-speed='" + speedStr + "']").addClass("is-active");
103 audiobooks = JSON.parse(localStorage["audiobook-history"]);
107 last = audiobooks[$root.attr("data-book-slug")]
108 // Fallback for book id;
110 last = audiobooks[$root.attr("data-book-id")]
114 initialElem = $('[data-media-id="' + last[1] + '"]', $root).first();
115 initialTime = last[2];
118 setMedia(initialElem, initialTime);
121 timeupdate: function(event) {
122 t = event.jPlayer.status.currentTime;
123 ttl = (totalDurationLeft - t) / speed;
124 ttl = $.jPlayer.convertTime(ttl);
125 $(".total-time-left").text('Czas do końca: ' + ttl);
127 $(".time-left").text('– ' + $.jPlayer.convertTime(
132 if (Math.abs(t - lastUpdate) > 3) {
134 audiobooks = JSON.parse(localStorage["audiobook-history"]);
138 if (t && event.jPlayer.status.duration - t > 10) {
139 audiobooks[$root.attr("data-book-slug")] = [
141 event.jPlayer.status.media.id,
142 event.jPlayer.status.currentTime
145 delete audiobooks[$root.attr("data-book-slug")];
147 // Remove old book id, if present.
148 delete audiobooks[$root.attr("data-book-id")];
149 localStorage["audiobook-history"] = JSON.stringify(audiobooks);
155 ended: function(event) {
156 let p = $currentMedia.next();
158 setMedia(p).jPlayer("play");