mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-14 00:06:17 -08:00
`art.play()` is an async wrapper around the native `video.play()` promise, which rejects when a pending play request is interrupted (`pause()`, `load()`, a new `src`, or the element being removed) and when autoplay is blocked. Every internal caller fires it from an event handler and cannot await it, so the rejection escapes as a global `unhandledrejection`. Error trackers report it as an uncaught crash even though the player recovers on its own — for example destroying the player right after mount, which is routine when the video sits in a modal the user can close quickly. Add a `silencePromise` util (the same approach video.js uses) and apply it to the non-awaited internal call sites: mask, play control, mini player, loop restart, autoPlayback jump, hotkey and click toggles. `switchMix` is fixed too, for a second symptom: `await art.play()` inside the async `video:canplay` handler both leaked the rejection and left the `switchUrl` promise pending forever, since the throw never reached the enclosing executor's `reject`. It now settles. The public API is unchanged: `art.play()` and `art.toggle()` still return the original promise, so applications that call them keep their own rejection to handle. Only the internal, non-awaited copy is silenced.
24 lines
610 B
JavaScript
24 lines
610 B
JavaScript
import { append, setStyle, silencePromise } from './utils'
|
|
import Component from './utils/component'
|
|
|
|
export default class Mask extends Component {
|
|
constructor(art) {
|
|
super(art)
|
|
|
|
this.name = 'mask'
|
|
const { template, icons, events } = art
|
|
|
|
const $state = append(template.$state, icons.state)
|
|
const $error = append(template.$state, icons.error)
|
|
|
|
setStyle($error, 'display', 'none')
|
|
|
|
art.on('destroy', () => {
|
|
setStyle($state, 'display', 'none')
|
|
setStyle($error, 'display', null)
|
|
})
|
|
|
|
events.proxy(template.$state, 'click', () => silencePromise(art.play()))
|
|
}
|
|
}
|