AssetManager
- Load and unload image, video, audio and data assets
- Reduces memory consumption
- Easy to use
- No dependencies
Installation
npm install @mediamonks/assetmanager
Usage
import assetManager from '@mediamonks/assetmanager';
assetManager.load('https://catpics.com/cat.png');
assetManager.load(['meow.mp3', 'lol.wav']);
assetManager.load(['data/data.json', 'videos/video.mp4'], 'main');
assetManager.load(aLotOfFiles, progress => {
console.log(`${Math.floor(progress * 100)}%`);
});
assetManager.load(allTheFiles, 'files', progress => {
console.log(`${Math.floor(progress * 100)}%`);
});
image.src = assetManager.get('https://catpics.com/cat.png');
video.src = assetManager.get('videos/video.mp4');
const audioContext = new AudioContext();
const source = audioContext.createBufferSource();
source.buffer = assetManager.get('meow.mp3');
source.start();
const data = assetManager.get('data/data.json');
assetManager.release('meow.mp3');
assetManager.release(['meow.mp3', 'lol.wav']);
assetManager.release('main');
assetManager.release();
In Vue.js
import assetManager from '@mediamonks/assetmanager';
Vue.use(assetManager, { root: 'assets/' });
Loading/using/unloading in a component
this.$assets.load(['image.png', 'data.json']);
const { value } = this.$assets.get('data.json');
this.$assets.release('data.json');
Using in a template
<img :src="$assets.get(...)" />