1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Polyfill HTMLMediaElement.play

Return a `Promise` to match the new standard.
This commit is contained in:
Dmitry Lyzo 2022-02-26 13:28:16 +03:00
parent 801c29d3b9
commit 270430f6a1
3 changed files with 41 additions and 21 deletions

View file

@ -197,28 +197,21 @@ import { Events } from 'jellyfin-apiclient';
export function playWithPromise(elem, onErrorFn) {
try {
const promise = elem.play();
if (promise && promise.then) {
// Chrome now returns a promise
return promise
.catch((e) => {
const errorName = (e.name || '').toLowerCase();
// safari uses aborterror
if (errorName === 'notallowederror' ||
errorName === 'aborterror') {
// swallow this error because the user can still click the play button on the video element
return Promise.resolve();
}
return Promise.reject();
})
.then(() => {
onSuccessfulPlay(elem, onErrorFn);
return elem.play()
.catch((e) => {
const errorName = (e.name || '').toLowerCase();
// safari uses aborterror
if (errorName === 'notallowederror' ||
errorName === 'aborterror') {
// swallow this error because the user can still click the play button on the video element
return Promise.resolve();
});
} else {
onSuccessfulPlay(elem, onErrorFn);
return Promise.resolve();
}
}
return Promise.reject();
})
.then(() => {
onSuccessfulPlay(elem, onErrorFn);
return Promise.resolve();
});
} catch (err) {
console.error('error calling video.play: ' + err);
return Promise.reject();