8000 fix: replay button broken for native playback (#8142) · videojs/video.js@b7116be · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit b7116be

Browse files
authored
fix: replay button broken for native playback (#8142)
* fix: replay button broken for native playback * remove debug logging * move fix to player * comment * add unit test * add native browser stubs * reset stubs and test currentTime
1 parent 2a99a78 commit b7116be

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/js/player.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -2320,6 +2320,7 @@ class Player extends Component {
23202320
this.playCallbacks_.push(callback);
23212321

23222322
const isSrcReady = Boolean(!this.changingSrc_ && (this.src() || this.currentSrc()));
2323+
const isSafariOrIOS = Boolean(browser.IS_ANY_SAFARI || browser.IS_IOS);
23232324

23242325
// treat calls to play_ somewhat like the `one` event function
23252326
if (this.waitToPlay_) {
@@ -2337,7 +2338,7 @@ class Player extends Component {
23372338

23382339
// if we are in Safari, there is a high chance that loadstart will trigger after the gesture timeperiod
23392340
// in that case, we need to prime the video element by calling load so it'll be ready in time
2340-
if (!isSrcReady && (browser.IS_ANY_SAFARI || browser.IS_IOS)) {
2341+
if (!isSrcReady && isSafariOrIOS) {
23412342
this.load();
23422343
}
23432344
return;
@@ -2346,6 +2347,12 @@ class Player extends Component {
23462347
// If the player/tech is ready and we have a source, we can attempt playback.
23472348
const val = this.techGet_('play');
23482349

2350+
// For native playback, reset the progress bar if we get a play call from a replay.
2351+
const isNativeReplay = isSafariOrIOS && this.hasClass('vjs-ended');
2352+
2353+
if (isNativeReplay) {
2354+
this.resetProgressBar_();
2355+
}
23492356
// play was terminated if the returned value is null
23502357
if (val === null) {
23512358
this.runPlayTerminatedQueue_();

test/unit/player-play.test.js

+33
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sinon from 'sinon';
33
import {silencePromise} from '../../src/js/utils/promise';
44
import TestHelpers from './test-helpers';
5+
import * as browser from '../../src/js/utils/browser.js';
56

67
QUnit.module('Player#play', {
78

@@ -104,3 +105,35 @@ QUnit.test('tech ready + has source + changing source = wait for loadstart', fun
104105
this.player.trigger('loadstart');
105106
assert.strictEqual(this.techPlayCallCount, 1, 'tech_.play was called');
106107
});
108+
109+
QUnit.test('play call from native replay calls resetProgressBar_', function(assert) {
110+
const origSafari = browser.IS_ANY_SAFARI;
111+
const origIOS = browser.IS_IOS;
112+
113+
browser.stub_IS_ANY_SAFARI(true);
114+
115+
// Mock the player having a source.
116+
this.player.src('xyz.mp4');
117+
this.clock.tick(100);
118+
119+
// Attempt to play, but silence the promise that might be returned.
120+
silencePromise(this.player.play());
121+
assert.strictEqual(this.techPlayCallCount, 1, 'tech_.play was called');
122+
123+
// add vjs-ended for replay logic and play again.
124+
this.player.addClass('vjs-ended');
125+
126+
silencePromise(this.player.play());
127+
assert.strictEqual(this.techPlayCallCount, 2, 'tech_.play was called');
128+
assert.strictEqual(this.techCurrentTimeCallCount, 1, 'tech_.currentTime was called');
129+
130+
// Reset safari stub and try replay in iOS.
131+
browser.stub_IS_ANY_SAFARI(origSafari);
132+
browser.stub_IS_IOS(true);
133+
134+
silencePromise(this.player.play());
135+
assert.strictEqual(this.techPlayCallCount, 3, 'tech_.play was called');
136+
assert.strictEqual(this.techCurrentTimeCallCount, 2, 'tech_.currentTime was called');
137+
138+
browser.stub_IS_IOS(origIOS);
139+
});

0 commit comments

Comments
 (0)
0