Skip to content

Commit cbbe99b

Browse files
committed
Fix bug with playing at non-zero start time
1 parent 373df7e commit cbbe99b

File tree

8 files changed

+69
-132
lines changed

8 files changed

+69
-132
lines changed

build/ableplayer.dist.js

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
else {
103103
this.startTime = 0;
104104
}
105-
106105
if ($(media).data('transcript-div') !== undefined && $(media).data('transcript-div') !== "") {
107106
this.transcriptDivLocation = $(media).data('transcript-div');
108107
}
@@ -263,13 +262,6 @@
263262
if (thisObj.countProperties(thisObj.tt) > 50) {
264263
// close enough to ensure that most text variables are populated
265264
thisObj.setup();
266-
if (thisObj.startTime > 0 && !thisObj.autoplay) {
267-
// scrub ahead to startTime, but don't start playing
268-
// can't do this in media event listener
269-
// because in some browsers no media events are fired until media.play is requested
270-
// even if preload="auto"
271-
thisObj.onMediaUpdateTime();
272-
}
273265
}
274266
else {
275267
// can't continue loading player with no text
@@ -6349,7 +6341,6 @@
63496341

63506342
(function ($) {
63516343
AblePlayer.prototype.seekTo = function (newTime) {
6352-
63536344
this.seeking = true;
63546345
this.liveUpdatePending = true;
63556346

@@ -6361,8 +6352,8 @@
63616352
seekable = this.media.seekable;
63626353
if (seekable.length > 0 && this.startTime >= seekable.start(0) && this.startTime <= seekable.end(0)) {
63636354
// successfully scrubbed to this.startTime
6355+
// this.seeking will be set to false in mediaUpdateTime()
63646356
this.media.currentTime = this.startTime;
6365-
this.seeking = false;
63666357
if (this.hasSignLanguage && this.signVideo) {
63676358
// keep sign languge video in sync
63686359
this.signVideo.currentTime = this.startTime;
@@ -8849,29 +8840,7 @@
88498840
AblePlayer.prototype.onMediaUpdateTime = function () {
88508841

88518842
var currentTime = this.getElapsed();
8852-
if (this.player === 'html5' && !this.startedPlaying) {
8853-
if (typeof this.startTime !== 'undefined') {
8854-
8855-
if (this.startTime === currentTime) {
8856-
// media has already scrubbed to start time
8857-
if (this.autoplay || (this.seeking && this.playing)) {
8858-
this.playMedia();
8859-
}
8860-
}
8861-
else {
8862-
// seek ahead until currentTime == startTime
8863-
this.seekTo(this.startTime);
8864-
}
8865-
}
8866-
else {
8867-
// autoplay should generally be avoided unless a startTime is provided
8868-
// but we'll trust the developer to be using this feature responsibly
8869-
if (this.autoplay) {
8870-
this.playMedia();
8871-
}
8872-
}
8873-
}
8874-
else if (this.swappingSrc && (typeof this.swapTime !== 'undefined')) {
8843+
if (this.swappingSrc && (typeof this.swapTime !== 'undefined')) {
88758844
if (this.swapTime === currentTime) {
88768845
// described version been swapped and media has scrubbed to time of previous version
88778846
if (this.playing) {
@@ -8883,12 +8852,8 @@
88838852
}
88848853
}
88858854
}
8886-
else if (this.player === 'youtube' && !this.startedPlaying) {
8887-
if (this.autoplay) {
8888-
this.playMedia();
8889-
}
8890-
}
8891-
if (!this.swappingSrc) {
8855+
else if (this.startedPlaying) {
8856+
// do all the usual time-sync stuff during playback
88928857
if (this.prefHighlight === 1) {
88938858
this.highlightTranscript(currentTime);
88948859
}
@@ -8898,6 +8863,20 @@
88988863
this.updateMeta();
88998864
this.refreshControls();
89008865
}
8866+
else if (this.seeking) {
8867+
if (this.startTime === currentTime) {
8868+
// media has scrubbed to start time
8869+
this.seeking = false;
8870+
if (this.autoplay || this.playing) {
8871+
this.playMedia();
8872+
}
8873+
}
8874+
}
8875+
else { // not swapping src, not started playing, not seeking
8876+
if (this.autoplay) {
8877+
this.playMedia();
8878+
}
8879+
}
89018880
};
89028881

89038882
AblePlayer.prototype.onMediaPause = function () {
@@ -9201,15 +9180,15 @@
92019180
if (thisObj.debug) {
92029181

92039182
}
9204-
if (thisObj.startTime && thisObj.seeking && !thisObj.startedPlaying) {
9183+
if (thisObj.startTime > 0 && !thisObj.startedPlaying) {
92059184
thisObj.seekTo(thisObj.startTime);
92069185
}
92079186
})
92089187
.on('canplaythrough',function() {
92099188
if (thisObj.debug) {
92109189

92119190
}
9212-
if (thisObj.startTime && thisObj.seeking && !thisObj.startedPlaying) {
9191+
if (thisObj.startTime && !thisObj.startedPlaying) {
92139192
// try again, if seeking failed on canplay
92149193
thisObj.seekTo(thisObj.startTime);
92159194
}

build/ableplayer.js

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
else {
103103
this.startTime = 0;
104104
}
105-
106105
if ($(media).data('transcript-div') !== undefined && $(media).data('transcript-div') !== "") {
107106
this.transcriptDivLocation = $(media).data('transcript-div');
108107
}
@@ -263,13 +262,6 @@
263262
if (thisObj.countProperties(thisObj.tt) > 50) {
264263
// close enough to ensure that most text variables are populated
265264
thisObj.setup();
266-
if (thisObj.startTime > 0 && !thisObj.autoplay) {
267-
// scrub ahead to startTime, but don't start playing
268-
// can't do this in media event listener
269-
// because in some browsers no media events are fired until media.play is requested
270-
// even if preload="auto"
271-
thisObj.onMediaUpdateTime();
272-
}
273265
}
274266
else {
275267
// can't continue loading player with no text
@@ -6349,7 +6341,6 @@
63496341

63506342
(function ($) {
63516343
AblePlayer.prototype.seekTo = function (newTime) {
6352-
63536344
this.seeking = true;
63546345
this.liveUpdatePending = true;
63556346

@@ -6361,8 +6352,8 @@
63616352
seekable = this.media.seekable;
63626353
if (seekable.length > 0 && this.startTime >= seekable.start(0) && this.startTime <= seekable.end(0)) {
63636354
// successfully scrubbed to this.startTime
6355+
// this.seeking will be set to false in mediaUpdateTime()
63646356
this.media.currentTime = this.startTime;
6365-
this.seeking = false;
63666357
if (this.hasSignLanguage && this.signVideo) {
63676358
// keep sign languge video in sync
63686359
this.signVideo.currentTime = this.startTime;
@@ -8849,29 +8840,7 @@
88498840
AblePlayer.prototype.onMediaUpdateTime = function () {
88508841

88518842
var currentTime = this.getElapsed();
8852-
if (this.player === 'html5' && !this.startedPlaying) {
8853-
if (typeof this.startTime !== 'undefined') {
8854-
8855-
if (this.startTime === currentTime) {
8856-
// media has already scrubbed to start time
8857-
if (this.autoplay || (this.seeking && this.playing)) {
8858-
this.playMedia();
8859-
}
8860-
}
8861-
else {
8862-
// seek ahead until currentTime == startTime
8863-
this.seekTo(this.startTime);
8864-
}
8865-
}
8866-
else {
8867-
// autoplay should generally be avoided unless a startTime is provided
8868-
// but we'll trust the developer to be using this feature responsibly
8869-
if (this.autoplay) {
8870-
this.playMedia();
8871-
}
8872-
}
8873-
}
8874-
else if (this.swappingSrc && (typeof this.swapTime !== 'undefined')) {
8843+
if (this.swappingSrc && (typeof this.swapTime !== 'undefined')) {
88758844
if (this.swapTime === currentTime) {
88768845
// described version been swapped and media has scrubbed to time of previous version
88778846
if (this.playing) {
@@ -8883,12 +8852,8 @@
88838852
}
88848853
}
88858854
}
8886-
else if (this.player === 'youtube' && !this.startedPlaying) {
8887-
if (this.autoplay) {
8888-
this.playMedia();
8889-
}
8890-
}
8891-
if (!this.swappingSrc) {
8855+
else if (this.startedPlaying) {
8856+
// do all the usual time-sync stuff during playback
88928857
if (this.prefHighlight === 1) {
88938858
this.highlightTranscript(currentTime);
88948859
}
@@ -8898,6 +8863,20 @@
88988863
this.updateMeta();
88998864
this.refreshControls();
89008865
}
8866+
else if (this.seeking) {
8867+
if (this.startTime === currentTime) {
8868+
// media has scrubbed to start time
8869+
this.seeking = false;
8870+
if (this.autoplay || this.playing) {
8871+
this.playMedia();
8872+
}
8873+
}
8874+
}
8875+
else { // not swapping src, not started playing, not seeking
8876+
if (this.autoplay) {
8877+
this.playMedia();
8878+
}
8879+
}
89018880
};
89028881

89038882
AblePlayer.prototype.onMediaPause = function () {
@@ -9201,15 +9180,15 @@
92019180
if (thisObj.debug) {
92029181
console.log('canplay event');
92039182
}
9204-
if (thisObj.startTime && thisObj.seeking && !thisObj.startedPlaying) {
9183+
if (thisObj.startTime > 0 && !thisObj.startedPlaying) {
92059184
thisObj.seekTo(thisObj.startTime);
92069185
}
92079186
})
92089187
.on('canplaythrough',function() {
92099188
if (thisObj.debug) {
92109189
console.log('canplaythrough event');
92119190
}
9212-
if (thisObj.startTime && thisObj.seeking && !thisObj.startedPlaying) {
9191+
if (thisObj.startTime && !thisObj.startedPlaying) {
92139192
// try again, if seeking failed on canplay
92149193
thisObj.seekTo(thisObj.startTime);
92159194
}

0 commit comments

Comments
 (0)