UNPKG

1.5 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.playAndHandleNotAllowedError = void 0;
4const playAndHandleNotAllowedError = (mediaRef, mediaType) => {
5 const { current } = mediaRef;
6 const prom = current === null || current === void 0 ? void 0 : current.play();
7 if (prom === null || prom === void 0 ? void 0 : prom.catch) {
8 prom === null || prom === void 0 ? void 0 : prom.catch((err) => {
9 if (!current) {
10 return;
11 }
12 // Pause was called after play in Chrome
13 if (err.message.includes('request was interrupted by a call to pause')) {
14 return;
15 }
16 // Pause was called after play in Safari
17 if (err.message.includes('The operation was aborted.')) {
18 return;
19 }
20 // Pause was called after play in Firefox
21 if (err.message.includes('The fetching process for the media resource was aborted by the user agent')) {
22 return;
23 }
24 console.log(`Could not play ${mediaType} due to following error: `, err);
25 if (!current.muted) {
26 console.log(`The video will be muted and we'll retry playing it.`, err);
27 current.muted = true;
28 current.play();
29 }
30 });
31 }
32};
33exports.playAndHandleNotAllowedError = playAndHandleNotAllowedError;
34//# sourceMappingURL=play-and-handle-not-allowed-error.js.map
\No newline at end of file