mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 06:31:20 -08:00
添加区间循环
This commit is contained in:
1 parent
35ac59dc45
commit
7d6186ddd6
4 files changed
+71
-1
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user