|
12 | 12 | } |
13 | 13 | }; |
14 | 14 |
|
15 | | - AblePlayer.prototype.updateChapter = function(now) { |
| 15 | + AblePlayer.prototype.updateChapter = function (now) { |
16 | 16 |
|
17 | | - // as time-synced chapters change during playback, update external container |
| 17 | + // as time-synced chapters change during playback, track changes in current chapter |
18 | 18 |
|
19 | | - if (typeof this.$chaptersDiv === 'undefined') { |
| 19 | + if (typeof this.chapters === 'undefined') { |
20 | 20 | return; |
21 | 21 | } |
| 22 | + |
22 | 23 | var chapters, i, thisChapterIndex, chapterLabel; |
| 24 | + |
23 | 25 | chapters = this.chapters; |
24 | 26 | for (i in chapters) { |
25 | 27 | if ((chapters[i].start <= now) && (chapters[i].end > now)) { |
|
30 | 32 | if (typeof thisChapterIndex !== 'undefined') { |
31 | 33 | if (this.currentChapter !== chapters[thisChapterIndex]) { |
32 | 34 | // this is a new chapter |
33 | | - this.$chaptersDiv.find('ul').find('li').removeClass('able-current-chapter').attr('aria-selected',''); |
34 | | - this.$chaptersDiv.find('ul').find('li').eq(thisChapterIndex) |
35 | | - .addClass('able-current-chapter').attr('aria-selected','true'); |
36 | 35 | this.currentChapter = chapters[thisChapterIndex]; |
| 36 | + if (this.useChapterTimes) { |
| 37 | + this.chapterDuration = this.getChapterDuration(); |
| 38 | + this.seekIntervalCalculated = false; // will be recalculated in setSeekInterval() |
| 39 | + } |
| 40 | + if (typeof this.$chaptersDiv !== 'undefined') { |
| 41 | + // chapters are listed in an external container |
| 42 | + this.$chaptersDiv.find('ul').find('li').removeClass('able-current-chapter').attr('aria-selected',''); |
| 43 | + this.$chaptersDiv.find('ul').find('li').eq(thisChapterIndex) |
| 44 | + .addClass('able-current-chapter').attr('aria-selected','true'); |
| 45 | + } |
| 46 | + // announce new chapter via ARIA alert |
37 | 47 | chapterLabel = this.tt.newChapter + ': ' + this.flattenCueForCaption(this.currentChapter); |
38 | 48 | this.showAlert(chapterLabel,'screenreader'); |
39 | 49 | } |
40 | 50 | } |
41 | 51 | }; |
42 | 52 |
|
| 53 | + AblePlayer.prototype.getChapterDuration = function () { |
| 54 | + |
| 55 | + // called if this.seekbarScope === 'chapter' |
| 56 | + // get duration of the current chapter |
| 57 | + |
| 58 | + var videoDuration, lastChapterIndex, chapterEnd; |
| 59 | + |
| 60 | + if (typeof this.currentChapter === 'undefined') { |
| 61 | + return duration; |
| 62 | + } |
| 63 | + videoDuration = this.getDuration(); |
| 64 | + lastChapterIndex = this.chapters.length-1; |
| 65 | + if (this.chapters[lastChapterIndex] == this.currentChapter) { |
| 66 | + // this is the last chapter |
| 67 | + if (this.currentChapter.end !== videoDuration) { |
| 68 | + // chapter ends before or after video ends, adjust chapter end to match video end |
| 69 | + chapterEnd = videoDuration; |
| 70 | + this.currentChapter.end = videoDuration; |
| 71 | + } |
| 72 | + else { |
| 73 | + chapterEnd = this.currentChapter.end; |
| 74 | + } |
| 75 | + } |
| 76 | + else { // this is not the last chapter |
| 77 | + chapterEnd = this.currentChapter.end; |
| 78 | + } |
| 79 | + return chapterEnd - this.currentChapter.start; |
| 80 | + }; |
| 81 | + |
| 82 | + AblePlayer.prototype.getChapterElapsed = function () { |
| 83 | + |
| 84 | + // called if this.seekbarScope === 'chapter' |
| 85 | + // get current elapsed time, relative to the current chapter duration |
| 86 | + if (typeof this.currentChapter === 'undefined') { |
| 87 | + return elapsed; |
| 88 | + } |
| 89 | + var videoDuration = this.getDuration(); |
| 90 | + var videoElapsed = this.getElapsed(); |
| 91 | + if (videoElapsed > this.currentChapter.start) { |
| 92 | + return videoElapsed - this.currentChapter.start; |
| 93 | + } |
| 94 | + else { |
| 95 | + return 0; |
| 96 | + } |
| 97 | + }; |
| 98 | + |
| 99 | + AblePlayer.prototype.convertChapterTimeToVideoTime = function (chapterTime) { |
| 100 | + |
| 101 | + // chapterTime is the time within the current chapter |
| 102 | + // return the same time, relative to the entire video |
| 103 | + var newTime = this.currentChapter.start + chapterTime; |
| 104 | + if (newTime > this.currentChapter.end) { |
| 105 | + return this.currentChapter.end; |
| 106 | + } |
| 107 | + else { |
| 108 | + return newTime; |
| 109 | + } |
| 110 | + }; |
| 111 | + |
43 | 112 | })(jQuery); |
0 commit comments