forked from a-angelov/info
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.mediaChapters.js
46 lines (37 loc) · 1.38 KB
/
jquery.mediaChapters.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(function ($) {
$.fn.mediaChapter = function (options) {
// create object to store variables
var defaults = {
audioElementSelector: '.audio', // Default audio player that will load the audio file
audioChapterSelector: '.loader' // Default element that will have the data-timestamp for the chapter
};
options = $.extend({}, defaults, options);
var $audio = $(options.audioElementSelector)
$(this).each(function () {
var $el = $(this);
// Click on the specified element to load .mp3 into audio tag
var path = $el.data('recording');
$el.on('click', function () {
// Load the audio file for the selected episode
$audio.attr({
src: path
});
return false;
});
var $chapters = $el.find(options.audioChapterSelector);
console.log($chapters);
// Click on Segment, Set timestamp in audioplayer - autoplay
$chapters.on('click', function () {
var timestamp = $(this).data('timestamp').split(':'),
minutes = parseInt(timestamp[0] * 60, 10),
seconds = parseInt(timestamp[1], 10);
// Give the audio player the timestamp of the segment
console.log($audio.get(0))
$audio.get(0).currentTime = minutes + seconds
$audio.get(0).play();
return false;
});
})
return this;
};
})(jQuery);