Skip to content

Commit

Permalink
fix(FEC-11904): Player_Web_Mac - The spinner appears when unmute the …
Browse files Browse the repository at this point in the history
…show (#645)

Safari fires WAITING event once unmuting and immediately sends PLAYING
so prevent sending waiting event for too short buffering

Solves FEC-11904
  • Loading branch information
yairans committed Mar 15, 2022
1 parent 5c1b284 commit c0ca395
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/engines/html5/html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import getLogger from '../../utils/logger';
import {DroppedFramesWatcher} from '../dropped-frames-watcher';
import {ThumbnailInfo} from '../../thumbnail/thumbnail-info';

const SHORT_BUFFERING_TIMEOUT: number = 200;

/**
* Html5 engine for playback.
* @classdesc
Expand Down Expand Up @@ -295,13 +297,14 @@ export default class Html5 extends FakeEventTarget implements IEngine {
*/
attach(): void {
Object.keys(Html5EventType).forEach(html5Event => {
if (Html5EventType[html5Event] !== Html5EventType.ERROR) {
if (![Html5EventType.ERROR, Html5EventType.WAITING].includes(Html5EventType[html5Event])) {
this._eventManager.listen(this._el, Html5EventType[html5Event], () => {
return this.dispatchEvent(new FakeEvent(Html5EventType[html5Event]));
});
}
});
this._eventManager.listen(this._el, Html5EventType.ERROR, () => this._handleVideoError());
this._eventManager.listen(this._el, Html5EventType.WAITING, () => this._handleWaiting());
this._handleMetadataTrackEvents();
this._eventManager.listen(this._el.textTracks, 'addtrack', (event: any) => {
if (PKTextTrack.isNativeTextTrack(event.track)) {
Expand Down Expand Up @@ -1145,6 +1148,17 @@ export default class Html5 extends FakeEventTarget implements IEngine {
}
}

_handleWaiting(): void {
let playing = false;
this._eventManager.listenOnce(this._el, Html5EventType.PLAYING, () => (playing = true));
setTimeout(() => {
// prevent sending waiting event for too short buffering
if (!playing) {
this.dispatchEvent(new FakeEvent(Html5EventType.WAITING));
}
}, SHORT_BUFFERING_TIMEOUT);
}

/**
* more info about the error
* @returns {string} info about the video element error
Expand Down
15 changes: 15 additions & 0 deletions test/src/engines/html5/html5.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Html5 from '../../../../src/engines/html5/html5';
import BaseMediaSourceAdapter from '../../../../src/engines/html5/media-source/base-media-source-adapter';
import sourcesConfig from '../../configs/sources.json';
import {DroppedFramesWatcher} from '../../../../src/engines/dropped-frames-watcher';
import {Html5EventType} from '../../../../src/event/event-type';

describe('Html5', () => {
let sandbox;
Expand Down Expand Up @@ -31,6 +32,20 @@ describe('Html5', () => {
engine._el.should.be.a('HTMLVideoElement');
});

it('should prevent too short buffering event', done => {
const progressiveSource = sourcesConfig.Mp4.progressive[0];
const engine = Html5.createEngine(progressiveSource);
engine._eventManager.listen(engine, Html5EventType.WAITING, () => {
done();
});
engine._el.dispatchEvent(new window.Event(Html5EventType.WAITING));
engine._el.dispatchEvent(new window.Event(Html5EventType.PLAYING));
engine._el.dispatchEvent(new window.Event(Html5EventType.WAITING));
setTimeout(() => {
engine._el.dispatchEvent(new window.Event(Html5EventType.PLAYING));
}, 300);
});

it('should restore html5 engine', () => {
const progressiveSource = sourcesConfig.Mp4.progressive[0];
const config = {
Expand Down

0 comments on commit c0ca395

Please sign in to comment.