mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 19:06:15 -08:00
39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
import { secondToTime, setStyle } from '../utils';
|
|
|
|
export default function autoPlayback(art) {
|
|
const {
|
|
i18n,
|
|
storage,
|
|
constructor,
|
|
template: { $poster },
|
|
} = art;
|
|
|
|
art.on('video:timeupdate', () => {
|
|
const times = storage.get('times') || {};
|
|
const keys = Object.keys(times);
|
|
if (keys.length > constructor.AUTO_PLAYBACK_MAX) delete times[keys[0]];
|
|
times[art.option.url] = art.currentTime;
|
|
storage.set('times', times);
|
|
});
|
|
|
|
art.on('ready', () => {
|
|
const times = storage.get('times') || {};
|
|
const currentTime = times[art.option.url];
|
|
if (currentTime) {
|
|
art.seek = currentTime;
|
|
setStyle($poster, 'display', 'none');
|
|
art.notice.show = `${i18n.get('Auto playback at')} ${secondToTime(currentTime)}`;
|
|
}
|
|
});
|
|
|
|
return {
|
|
name: 'autoPlayback',
|
|
get times() {
|
|
return storage.get('times') || {};
|
|
},
|
|
clear() {
|
|
return storage.del('times');
|
|
},
|
|
};
|
|
}
|