mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-20 20:21:20 -08:00
Merge pull request #1058 from acaliskol/fix/unhandled-play-rejection
fix: silence unhandled play() rejections from internal callers
This commit is contained in:
21 files changed
+216
-43
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { append, setStyle, tooltip } from '../utils'
|
||||
import { append, setStyle, silencePromise, tooltip } from '../utils'
|
||||
|
||||
export default function playAndPause(option) {
|
||||
return art => ({
|
||||
@@ -12,7 +12,7 @@ export default function playAndPause(option) {
|
||||
tooltip($pause, i18n.get('Pause'))
|
||||
|
||||
proxy($play, 'click', () => {
|
||||
art.play()
|
||||
silencePromise(art.play())
|
||||
})
|
||||
|
||||
proxy($pause, 'click', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { includeFromEvent, isMobile } from '../utils'
|
||||
import { includeFromEvent, isMobile, silencePromise } from '../utils'
|
||||
|
||||
export default function clickInit(art, events) {
|
||||
const {
|
||||
@@ -35,11 +35,11 @@ export default function clickInit(art, events) {
|
||||
|
||||
if (isMobile) {
|
||||
if (!art.isLock && MOBILE_CLICK_PLAY) {
|
||||
art.toggle()
|
||||
silencePromise(art.toggle())
|
||||
}
|
||||
}
|
||||
else {
|
||||
art.toggle()
|
||||
silencePromise(art.toggle())
|
||||
}
|
||||
clickTimes = clicks
|
||||
break
|
||||
@@ -48,7 +48,7 @@ export default function clickInit(art, events) {
|
||||
|
||||
if (isMobile) {
|
||||
if (!art.isLock && MOBILE_DBCLICK_PLAY) {
|
||||
art.toggle()
|
||||
silencePromise(art.toggle())
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { isMobile } from './utils'
|
||||
import { isMobile, silencePromise } from './utils'
|
||||
|
||||
export default class Hotkey {
|
||||
constructor(art) {
|
||||
@@ -21,7 +21,7 @@ export default class Hotkey {
|
||||
})
|
||||
|
||||
this.add('Space', () => {
|
||||
this.art.toggle()
|
||||
silencePromise(this.art.toggle())
|
||||
})
|
||||
|
||||
this.add('ArrowLeft', () => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { append, setStyle } from './utils'
|
||||
import { append, setStyle, silencePromise } from './utils'
|
||||
import Component from './utils/component'
|
||||
|
||||
export default class Mask extends Component {
|
||||
@@ -18,6 +18,6 @@ export default class Mask extends Component {
|
||||
setStyle($error, 'display', null)
|
||||
})
|
||||
|
||||
events.proxy(template.$state, 'click', () => art.play())
|
||||
events.proxy(template.$state, 'click', () => silencePromise(art.play()))
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import config from '../config'
|
||||
import { addClass, isMobile, setStyle, sleep } from '../utils'
|
||||
import { addClass, isMobile, setStyle, silencePromise, sleep } from '../utils'
|
||||
|
||||
export default function eventInit(art) {
|
||||
const {
|
||||
@@ -51,7 +51,7 @@ export default function eventInit(art) {
|
||||
art.on('video:ended', () => {
|
||||
if (option.loop) {
|
||||
art.seek = 0
|
||||
art.play()
|
||||
silencePromise(art.play())
|
||||
art.controls.show = false
|
||||
art.mask.show = false
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { addClass, append, createElement, def, getRect, hasClass, isInViewport, removeClass, setStyle } from '../utils'
|
||||
import { addClass, append, createElement, def, getRect, hasClass, isInViewport, removeClass, setStyle, silencePromise } from '../utils'
|
||||
|
||||
export default function miniMix(art) {
|
||||
const {
|
||||
@@ -53,7 +53,7 @@ export default function miniMix(art) {
|
||||
const $state = append($mini, `<div class="art-mini-state"></div>`)
|
||||
const $play = append($state, icons.play)
|
||||
const $pause = append($state, icons.pause)
|
||||
proxy($play, 'click', () => art.play())
|
||||
proxy($play, 'click', () => silencePromise(art.play()))
|
||||
proxy($pause, 'click', () => art.pause())
|
||||
initState($play, $pause)
|
||||
art.on('video:playing', () => initState($play, $pause))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { def } from '../utils'
|
||||
import { def, silencePromise } from '../utils'
|
||||
|
||||
export default function switchMix(art) {
|
||||
function switchUrl(url, currentTime) {
|
||||
@@ -31,7 +31,7 @@ export default function switchMix(art) {
|
||||
art.aspectRatio = aspectRatio
|
||||
|
||||
if (playing) {
|
||||
await art.play()
|
||||
await silencePromise(art.play())
|
||||
}
|
||||
|
||||
art.notice.show = ''
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { append, query, secondToTime, setStyle } from '../utils'
|
||||
import { append, query, secondToTime, setStyle, silencePromise } from '../utils'
|
||||
|
||||
export default function autoPlayback(art) {
|
||||
const {
|
||||
@@ -57,7 +57,7 @@ export default function autoPlayback(art) {
|
||||
|
||||
proxy($jump, 'click', () => {
|
||||
art.seek = currentTime
|
||||
art.play()
|
||||
silencePromise(art.play())
|
||||
setStyle($poster, 'display', 'none')
|
||||
setStyle($autoPlayback, 'display', 'none')
|
||||
})
|
||||
|
||||
@@ -14,3 +14,12 @@ export function errorHandle(condition, msg) {
|
||||
}
|
||||
return condition
|
||||
}
|
||||
|
||||
// Handle internal play rejections without changing the public play/toggle promises.
|
||||
// Values without catch (including synchronous pause results) pass through unchanged.
|
||||
export function silencePromise(value) {
|
||||
if (value && typeof value.catch === 'function') {
|
||||
return value.catch(() => {})
|
||||
}
|
||||
return value
|
||||
}
|
||||
Reference in new issue
Block a user