-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- renamed methods, properties and options - added setMaxCachedImages - added loadProgress property
- Loading branch information
1 parent
10ee3db
commit 0373c79
Showing
10 changed files
with
230 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,32 @@ | ||
import { FastImageSequence } from '../../src/index'; | ||
import {FastImageSequence} from '../../src/index'; | ||
|
||
export async function initExampleStillImage(container) { | ||
const fastImageSequence = new FastImageSequence(container, { | ||
name: 'StillImageTest', | ||
frames: 89, | ||
imageURLCallback: (i) => `${('' + (i + 1)).padStart(4, '0')}.webp`, | ||
tarURL: 'lowrespreviews.tar', | ||
tarImageURLCallback: (i) => `${('' + (i+1)).padStart(4, '0')}.jpg`, | ||
// tarURL: 'lowrespreviews.tar', | ||
// tarImageURLCallback: (i) => `${('' + (i + 1)).padStart(4, '0')}.jpg`, | ||
|
||
// optional arguments: | ||
wrap: true, // default false | ||
size: 'cover', // default 'cover' | ||
loop: true, // default false | ||
objectFit: 'cover', // default 'cover' | ||
fillStyle: '#00000000', // default #00000000 | ||
preloadAllTarImages: false, | ||
useWorkerForTar: true, // default true | ||
numberOfCachedImages: 32, // default 32 | ||
maxCachedImages: 1, // default 32 | ||
clearCanvas: false, // default false | ||
showDebugInfo: true, | ||
}); | ||
|
||
await fastImageSequence.ready; | ||
|
||
console.log('fastImageSequence loaded'); | ||
|
||
// now the first frame is loaded (numberOfCachedImages = 1), wait for 2 seconds, and then preload the other the frames | ||
setTimeout(() => { | ||
fastImageSequence.setMaxCachedImages(89, (progress) => console.log('preload progress:', progress)).then(() => { | ||
console.log('all frames preloaded'); | ||
}); | ||
}, 2000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export function downloadFile(url: string, onProgress?: (progress: number) => void): Promise<ArrayBuffer> { | ||
return new Promise((resolve, reject) => { | ||
const xhr = new XMLHttpRequest(); | ||
xhr.open('GET', url, true); | ||
xhr.responseType = 'arraybuffer'; | ||
|
||
xhr.onprogress = function(event: ProgressEvent) { | ||
if (event.lengthComputable && onProgress) { | ||
const progress = event.loaded / event.total; | ||
onProgress(progress); | ||
} | ||
}; | ||
|
||
xhr.onload = function() { | ||
if (xhr.status === 200) { | ||
resolve(xhr.response); | ||
} else { | ||
reject(new Error(`Error ${xhr.status}: ${xhr.statusText}`)); | ||
} | ||
}; | ||
|
||
xhr.onerror = function() { | ||
reject(new Error('Request failed')); | ||
}; | ||
|
||
xhr.send(); | ||
}); | ||
} |
Oops, something went wrong.