Refactor progress event handling in progress.js

- Moved the 'video:progress' event listener to be consistent with the RAF and timeupdate events.
- Ensured 'setBar' for 'loaded' is emitted during both RAF and video:progress events.
- Cleaned up the structure for better readability and maintainability.
This commit is contained in:
Harvey Zack committed 2025-04-20 11:21:21 +08:00
1 parent 9bdaaa3b7d
commit 674c6420e9
3 files changed
+1132 -1110

No files matched your search

+9 -8
View File
@@ -125,23 +125,24 @@ export default function progress(options) {
art.on('setBar', setBar);
art.on('video:loadedmetadata', updateHighlight);
art.on('video:progress', () => {
art.emit('setBar', 'loaded', art.loaded);
});
if (art.constructor.USE_RAF) {
art.on('raf', () => {
art.emit('setBar', 'played', art.played);
art.emit('setBar', 'loaded', art.loaded);
});
} else {
art.on('video:timeupdate', () => {
art.emit('setBar', 'played', art.played);
});
}
art.on('video:ended', () => {
art.emit('setBar', 'played', 1);
});
art.on('video:progress', () => {
art.emit('setBar', 'loaded', art.loaded);
});
art.on('video:ended', () => {
art.emit('setBar', 'played', 1);
});
}
art.emit('setBar', 'loaded', art.loaded || 0);