mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-10 12:46:15 -08:00
24 lines
475 B
JavaScript
24 lines
475 B
JavaScript
import { getScope } from '../lifecycle/instance'
|
|
import { animationFrame } from '../lifecycle/resources'
|
|
|
|
export default function updateInit(art) {
|
|
if (art.constructor.USE_RAF) {
|
|
const scope = getScope(art)
|
|
let cancel = () => {};
|
|
|
|
(function update() {
|
|
if (art.playing) {
|
|
art.emit('raf')
|
|
}
|
|
|
|
if (!art.isDestroy) {
|
|
cancel = animationFrame(scope, update)
|
|
}
|
|
})()
|
|
|
|
art.on('destroy', () => {
|
|
cancel()
|
|
})
|
|
}
|
|
}
|