Skip to content

Commit e1fbd0e

Browse files
committed
Play automatically after click on restart, chapter, or within transcript
1 parent c7d6566 commit e1fbd0e

9 files changed

Lines changed: 51 additions & 15 deletions

File tree

build/ableplayer.dist.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3483,6 +3483,7 @@
34833483
trackLabel.text(this.flattenCueForCaption(track) + ' - ' + this.formatSecondsAsColonTime(track.start));
34843484
var getClickFunction = function (time) {
34853485
return function () {
3486+
thisObj.seekTrigger = 'chapter';
34863487
thisObj.seekTo(time);
34873488
// stopgap to prevent spacebar in Firefox from reopening popup
34883489
// immediately after closing it (used in handleChapters())
@@ -8741,6 +8742,7 @@
87418742
// add event listeners
87428743
getClickFunction = function (time) {
87438744
return function () {
8745+
thisObj.seekTrigger = 'chapter';
87448746
$clickedItem = $(this).closest('li');
87458747
$chaptersList = $(this).closest('ul').find('li');
87468748
thisChapterIndex = $chaptersList.index($clickedItem);
@@ -9254,13 +9256,14 @@
92549256
// Keydown events are handled elsehwere, both globally (ableplayer-base.js) and locally (event.js)
92559257
if (this.$transcriptArea.length > 0) {
92569258
this.$transcriptArea.find('span.able-transcript-seekpoint').click(function(event) {
9259+
thisObj.seekTrigger = 'transcript';
92579260
var spanStart = parseFloat($(this).attr('data-start'));
92589261
// Add a tiny amount so that we're inside the span.
92599262
spanStart += .01;
92609263
// Each click within the transcript triggers two click events (not sure why)
92619264
// this.seekingFromTranscript is a stopgab to prevent two calls to SeekTo()
9262-
if (!this.seekingFromTranscript) {
9263-
this.seekingFromTranscript = true;
9265+
if (!thisObj.seekingFromTranscript) {
9266+
thisObj.seekingFromTranscript = true;
92649267
thisObj.seekTo(spanStart);
92659268
}
92669269
else {
@@ -9984,12 +9987,15 @@
99849987
this.handlePlay();
99859988
}
99869989
else if (whichButton === 'restart') {
9990+
this.seekTrigger = 'restart';
99879991
this.handleRestart();
99889992
}
99899993
else if (whichButton === 'rewind') {
9994+
this.seekTrigger = 'rewind';
99909995
this.handleRewind();
99919996
}
99929997
else if (whichButton === 'forward') {
9998+
this.seekTrigger = 'forward';
99939999
this.handleFastForward();
999410000
}
999510001
else if (whichButton === 'mute') {
@@ -10154,7 +10160,13 @@
1015410160
// so we know player can seek ahead to anything
1015510161
})
1015610162
.on('canplaythrough',function() {
10157-
if (!thisObj.startedPlaying) {
10163+
if (thisObj.seekTrigger == 'restart' || thisObj.seekTrigger == 'chapter' || thisObj.seekTrigger == 'transcript') {
10164+
// by clicking on any of these elements, user is likely intending to play
10165+
// Not included: elements where user might click multiple times in succession
10166+
// (i.e., 'rewind', 'forward', or seekbar); for these, video remains paused until user initiates play
10167+
thisObj.playMedia();
10168+
}
10169+
else if (!thisObj.startedPlaying) {
1015810170
if (thisObj.startTime) {
1015910171
if (thisObj.seeking) {
1016010172
// a seek has already been initiated

build/ableplayer.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3483,6 +3483,7 @@
34833483
trackLabel.text(this.flattenCueForCaption(track) + ' - ' + this.formatSecondsAsColonTime(track.start));
34843484
var getClickFunction = function (time) {
34853485
return function () {
3486+
thisObj.seekTrigger = 'chapter';
34863487
thisObj.seekTo(time);
34873488
// stopgap to prevent spacebar in Firefox from reopening popup
34883489
// immediately after closing it (used in handleChapters())
@@ -8741,6 +8742,7 @@ console.log('resizeYouTubePlayer at POS Y1');
87418742
// add event listeners
87428743
getClickFunction = function (time) {
87438744
return function () {
8745+
thisObj.seekTrigger = 'chapter';
87448746
$clickedItem = $(this).closest('li');
87458747
$chaptersList = $(this).closest('ul').find('li');
87468748
thisChapterIndex = $chaptersList.index($clickedItem);
@@ -9254,13 +9256,14 @@ console.log('resizeYouTubePlayer at POS Y1');
92549256
// Keydown events are handled elsehwere, both globally (ableplayer-base.js) and locally (event.js)
92559257
if (this.$transcriptArea.length > 0) {
92569258
this.$transcriptArea.find('span.able-transcript-seekpoint').click(function(event) {
9259+
thisObj.seekTrigger = 'transcript';
92579260
var spanStart = parseFloat($(this).attr('data-start'));
92589261
// Add a tiny amount so that we're inside the span.
92599262
spanStart += .01;
92609263
// Each click within the transcript triggers two click events (not sure why)
92619264
// this.seekingFromTranscript is a stopgab to prevent two calls to SeekTo()
9262-
if (!this.seekingFromTranscript) {
9263-
this.seekingFromTranscript = true;
9265+
if (!thisObj.seekingFromTranscript) {
9266+
thisObj.seekingFromTranscript = true;
92649267
thisObj.seekTo(spanStart);
92659268
}
92669269
else {
@@ -9984,12 +9987,15 @@ console.log('resizeYouTubePlayer at POS Y1');
99849987
this.handlePlay();
99859988
}
99869989
else if (whichButton === 'restart') {
9990+
this.seekTrigger = 'restart';
99879991
this.handleRestart();
99889992
}
99899993
else if (whichButton === 'rewind') {
9994+
this.seekTrigger = 'rewind';
99909995
this.handleRewind();
99919996
}
99929997
else if (whichButton === 'forward') {
9998+
this.seekTrigger = 'forward';
99939999
this.handleFastForward();
999410000
}
999510001
else if (whichButton === 'mute') {
@@ -10154,7 +10160,13 @@ console.log('resizeYouTubePlayer at POS Y1');
1015410160
// so we know player can seek ahead to anything
1015510161
})
1015610162
.on('canplaythrough',function() {
10157-
if (!thisObj.startedPlaying) {
10163+
if (thisObj.seekTrigger == 'restart' || thisObj.seekTrigger == 'chapter' || thisObj.seekTrigger == 'transcript') {
10164+
// by clicking on any of these elements, user is likely intending to play
10165+
// Not included: elements where user might click multiple times in succession
10166+
// (i.e., 'rewind', 'forward', or seekbar); for these, video remains paused until user initiates play
10167+
thisObj.playMedia();
10168+
}
10169+
else if (!thisObj.startedPlaying) {
1015810170
if (thisObj.startTime) {
1015910171
if (thisObj.seeking) {
1016010172
// a seek has already been initiated

0 commit comments

Comments
 (0)