添加区间循环

This commit is contained in:
zhw2590582 committed 2020-05-17 00:39:44 +08:00
1 parent 35ac59dc45
commit 7d6186ddd6
4 files changed
+71 -1

No files matched your search

+2
View File
@@ -25,6 +25,7 @@ import rectMix from './rectMix';
import flipMix from './flipMix';
import lightMix from './lightMix';
import minMix from './minMix';
import loopMin from './loopMin';
import { proxyPropertys } from '../utils';
export default class Player {
@@ -56,6 +57,7 @@ export default class Player {
flipMix(art, this);
lightMix(art, this);
minMix(art, this);
loopMin(art, this);
proxyPropertys(art, this);
}
}
+33
View File
@@ -0,0 +1,33 @@
import { def, clamp } from '../utils';
export default function loopMin(art, player) {
let interval = [];
def(player, 'loop', {
get: () => interval,
set: (value) => {
if (Array.isArray(value) && typeof value[0] === 'number' && typeof value[1] === 'number') {
const start = clamp(value[0], 0, Math.min(value[1], player.duration));
const end = clamp(value[1], start, player.duration);
if (end - start >= 1) {
interval = [start, end];
art.emit('loop:add', interval);
} else {
interval = [];
art.emit('loop:remove');
}
} else {
interval = [];
art.emit('loop:remove');
}
},
});
art.on('video:timeupdate', () => {
if (interval.length) {
if (player.currentTime < interval[0] || player.currentTime > interval[1]) {
player.seek = interval[0];
art.emit('loop', interval);
}
}
});
}