UNPKG

1.54 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.playAndHandleNotAllowedError = void 0;
4const playAndHandleNotAllowedError = (mediaRef, mediaType) => {
5 const { current } = mediaRef;
6 if (!current) {
7 return;
8 }
9 const prom = current.play();
10 if (prom.catch) {
11 prom.catch((err) => {
12 if (!current) {
13 return;
14 }
15 // Pause was called after play in Chrome
16 if (err.message.includes('request was interrupted by a call to pause')) {
17 return;
18 }
19 // Pause was called after play in Safari
20 if (err.message.includes('The operation was aborted.')) {
21 return;
22 }
23 // Pause was called after play in Firefox
24 if (err.message.includes('The fetching process for the media resource was aborted by the user agent')) {
25 return;
26 }
27 // Got replaced by a different audio source in Chromium
28 if (err.message.includes('request was interrupted by a new load request')) {
29 return;
30 }
31 console.log(`Could not play ${mediaType} due to following error: `, err);
32 if (!current.muted) {
33 console.log(`The video will be muted and we'll retry playing it.`, err);
34 current.muted = true;
35 current.play();
36 }
37 });
38 }
39};
40exports.playAndHandleNotAllowedError = playAndHandleNotAllowedError;