Contact us

tel:15797766463

mail:business@seeshiontech.com

中文
English
中文
登录/注册

{user.username}

ID: {user.id}

VE Development document

Render Template

Update time : 2019-10-16 14:54:37

Render template to video

  1. Create an instance of SXTemplate by calling its contructor, pass template package file path and TemplateUsage.kForRender as arguments.
  2. Pass user asset files to SXTemplate instance by calling its setReplaceableFilePaths method.
  3. (Optional) If you want to make some percise modification to your SXTemaplate instance, you need call its commit method first. Then you can accesss assets and layers by their UI Keys.
  4. Create an instance of SXTemplateRender by calling its constructor, and passing your SXTemplate instance as an argument, you can also set a audio file as background audio by passing its file path as second argument, set the output file path by pass a absolute file pass as the third argument. The output file path must be a absolute file path that ends with .mp4 extension.
    You can also pass null to music path argument, then the rendering result will have template\'s default music file as background music(if the template has a default music file exported).
  5. Call the setRenderListener method of your SXTemplateRender instance to set a render status listener.
  6. Call the start method of your SXTemplateRender instance to start rendering.
  7. After rendering finished, set your SXTemplateRender instance and SXTemplate instance to null to free memory.

Example code

String folder = \"path/to/your/template/folder\";//unzipped template folder path
String[] paths = {\"user/asset/file/1.png\", \"user/asset/file/2.png\", \"user/asset/file/3.png\"}; //user asset files, used to replace template\'s editable asset files
SXTemplate template = new SXTemplate(mTemplateFolder, SXTemplate.TemplateUsage.kForRender);
template.setReplaceableFilePaths(paths);
template.commit();

String outputPath = \"path/to/your/output/file.mp4\";//absolute output video file path
SXTemplateRender render = new SXTemplateRender(template, null, outputPath);
//set render status listener
render.setRenderListener(new SXRenderListener() {
    @Override
    public void onStart() {
        // render started
    }
    @Override
    public void onUpdate(int progress) {
        // render updated, progress is current rendered frame count
    }
    @Override
    public void onFinish(boolean success, String msg) {
        // render finished, if failed, msg contains the error message 
    }
    @Override
    public void onCancel() {
        // render concelled by user
    }
});
render.start();

Error codes

If onFinish callback is called with the success argument as false, it means the render has filed.Then you can check the error code by calling getErrorCode method of SXTemplateRender class.

NO_ERROR = 0;   // No error  
UNKNOWN_ERROR = 1; // Unknown system error, you can check msg argument of onFinish for detail  
CANCELLED = 2; // Render is cancelled  
LICENSE_ERROR = 3; // License is invalid  
CODEC_ERROR = 4; // Media encoder error, can not encode video  
NETWORK_ERROR = 5; // Can not connect to network  
AUDIO_NOT_SUPPORT = 6; // Unsupported audio file encode format