Issue #802Opened January 25, 2018by goldengrisha0 reactions

Assets rendering

Question

I try to create a video thumbnail, when I add it like a tag it's working fine but when this an array or an object, it doesn't render it.

         let assetManager = this.editor.AssetManager;
         assetManager.addType('video', {
             view: {
                 getPreview() {
                     debugger;
                     return `<div style="text-align: center">video</div>`;
                 },
                 getInfo() {
                     return '<div>video description</div>';
                 }
             },
             isType(value) {
                 return value;
             }
         });

         assetManager.add('<video src="http://localhost:2195/malls/78620a57-d32f-40a5-9b06-003c2338c377/SampleVideo_1280x720_1mb.mp4" class="gjs-no-pointer" style="height: 100%; width: 100%;"></video>');
         assetManager.add([
             { type: 'video', src: 'http://localhost:2195/malls/78620a57-d32f-40a5-9b06-003c2338c377/SampleVideo_1280x720_1mb.mp4' },
             { type: 'video', src: 'http://localhost:2195/malls/78620a57-d32f-40a5-9b06-003c2338c377/SampleVideo_1280x720_1mb.mp4' }]);

Answers (3)

austinbiggsJanuary 26, 20180 reactions

@goldengrisha - I had an unrelated issue w/ thumbnails, as the asset manager simply loads in the full file for the thumbnail. When adding an asset, I now pass a thumbnail parameter and display that instead.

  getPreview: function getPreview() {
    var pfx = this.pfx;
    var src = this.model.get('src');
    var thumbnail = this.model.get('thumbnail');
    return '\n      <div class="' + pfx + 'preview" style="background-image: url(&#34;' + thumbnail + '&#34;);"></div>\n      <div class="' + pfx + 'preview-bg ' + this.ppfx + 'checker-bg"></div>\n    ';
  },
goldengrishaJanuary 26, 20180 reactions

thank you for answer, but point is why this code work in proper way assetManager.add('<video src="http://localhost:2195/malls/78620a57-d32f-40a5-9b06-003c2338c377/SampleVideo_1280x720_1mb.mp4" class="gjs-no-pointer" style="height: 100%; width: 100%;"></video>');

and this piece of code not : assetManager.add([ { type: 'video', src: 'http://localhost:2195/malls/78620a57-d32f-40a5-9b06-003c2338c377/SampleVideo_1280x720_1mb.mp4' }, { type: 'video', src: 'http://localhost:2195/malls/78620a57-d32f-40a5-9b06-003c2338c377/SampleVideo_1280x720_1mb.mp4' }]);

artfJanuary 29, 20180 reactions

@goldengrisha first of all, your isType(value) is not correct If you pass a string in assetManager.add the value will be that string and just by returning it you say nothing about its type (isType should return a Boolean or { type: 'something', ... }), moreover I think this doesn't make sense

assetManager.add('<video src="http://localhost:2195/malls/78620a57-d32f-40a5-9b06-003c2338c377/SampleVideo_1280x720_1mb.mp4" class="gjs-no-pointer" style="height: 100%; width: 100%;"></video>');

you're working with assets not Components, probably what you're looking for is something like this

assetManager.addType('video', {
			...
	  view: {
           getPreview() {
             const src = this.model.get('src');
             return `<div>
					<video 
						class="gjs-no-pointer" 
						style="height: 100%; width: 100%;"
						src="${src}">
					</video></div>`;
           },
		...
       },
       isType(value) {
				// eg. here you might check/parse/fetch url and try to 
				// understand the type
				if (isString(value) && propablyVideoUrl(value)) {
					return { type: 'video', src: value  }
				}
       }
});
assetManager.add('http://local ... 1mb.mp4');

If you add your assets via objects (eg. { type: 'video', src: '...', ... }) you don't even need isType as you're declaring it explicitly

Another good question, why you don't see your assetManager.add([ { type: 'video', src: ... which are actually correct?!? Well this is because by default OpenAssets command shows only images You can extend that Command and just rendering them in this way

const assets = assetManager.getAll();
assetManager.render(assets.filter(asset => asset.get('type') == 'video'))

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.