-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexampleLoadTar.js
65 lines (57 loc) · 2.12 KB
/
exampleLoadTar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import {FastImageSequence} from '../../src/index';
const prevButton = document.getElementById('prev-button-2');
const nextButton = document.getElementById('next-button-2');
const progress = document.getElementById('slider-input-2');
function blobToDataURL(blob) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = _e => resolve(reader.result);
reader.onerror = _e => reject(reader.error);
reader.onabort = _e => reject(new Error("Read aborted"));
reader.readAsDataURL(blob);
});
}
export async function initExampleLoadTar(container) {
// load tar file with lowres previews
fetch('lowrespreviews.tar').then(async (response) => {
const blob = await response.blob();
const dataURL = await blobToDataURL(blob);
const fastImageSequence = new FastImageSequence(container, {
name: 'LoadTar',
frames: 89,
src: [
{
tarURL: dataURL,
imageURL: (i) => `${('' + (i + 1)).padStart(4, '0')}.jpg`,
}
],
// optional arguments:
loop: true, // default false
objectFit: 'contain', // default 'cover'
fillStyle: '#00000000', // default #00000000
clearCanvas: false, // default false
showDebugInfo: true,
});
await fastImageSequence.ready();
fastImageSequence.tick((dt) => {
if (fastImageSequence.playing) {
progress.value = fastImageSequence.progress;
}
});
prevButton.addEventListener('click', () => {
fastImageSequence.play(-30);
});
nextButton.addEventListener('click', () => {
fastImageSequence.play(30);
});
progress.addEventListener('mousedown', (e) => {
fastImageSequence.stop();
});
progress.addEventListener('input', () => {
if (fastImageSequence.paused) {
fastImageSequence.progress = progress.value;
}
});
fastImageSequence.play(30);
});
}