Skip to content

In addition to using the http interface we provide, you can also build tasks, send tasks, and query tasks directly through Java code. You only need to import our internal jar package.

Add Maven dependencies

Add dependencies in pom.xml, the version number may change

xml
		<dependency>
			<groupId>com.meishesdk</groupId>
			<artifactId>cloudCompilesdk</artifactId>
			<version>1.1.22</version>
			<scope>system</scope>
			<systemPath>${project.basedir}/src/main/resources/lib/cloudCompileSdk-1.1.22-jar-with-dependencies.jar</systemPath>
		</dependency>

Writing Java code

The following is just a simple code example, primarily intended to illustrate the calling process from Java code. It's not intended to be used directly. If you have questions or don't understand something, please let us know your specific needs and we'll provide corresponding code examples.

java
package com.meishesdk.cloudcompilesdk.samples;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import com.meishesdk.cloudcompilesdk.models.xml.template.Caption;
import com.meishesdk.cloudcompilesdk.models.xml.template.Footage;
import com.meishesdk.cloudcompilesdk.models.xml.template.TemplateDom;
import com.meishesdk.cloudcompilesdk.models.xml.template.TopTemplateDom;
import com.meishesdk.cloudcompilesdk.task.CompileData;
import com.meishesdk.cloudcompilesdk.task.TaskClient;
import com.meishesdk.cloudcompilesdk.task.TaskInfo;
import com.meishesdk.cloudcompilesdk.task.TaskStateEnum;
import com.meishesdk.cloudcompilesdk.utils.Result;

public class TemplateSample {
    public static void main(String[] args) throws Exception {
        TopTemplateDom dom = new TemplateDom();
        dom.setTemplateId("2F864C33-E36A-4275-92EE-16F471E52DEF");
        dom.setOutputType("mp4");
        dom.setAspectRatio("16:9");

        List<Footage> footages = new ArrayList<>();
        dom.setFootages(footages);
        Footage f1 = new Footage();
        f1.setFootageId("footage1");
        f1.setPath("http://wslfile/demo.mp4");
        f1.setVolume(0.1);
        footages.add(f1);

        List<Caption> captions = new ArrayList<>();
        dom.setCaptions(captions);
        Caption c1 = new Caption();
        c1.setId("replace1");
        c1.setText("hello world 1");
        captions.add(c1);

        Caption c2 = new Caption();
        c2.setId("replace2");
        c2.setText("hello world 2");
        captions.add(c2);

        // Start the task
        TaskClient client = TaskClient.instanceOf("http://localhost:9999");
        String taskId = client.createTemplateCompileTask(dom);
        System.out.println(taskId);

        while (true) {
            TimeUnit.SECONDS.sleep(1);
            // Query tasks
            TaskInfo taskInfo = client.taskInfo(taskId);
            if (TaskStateEnum.FINISH.name().equalsIgnoreCase(taskInfo.getExecuteState())) {
                if (Result.SUCCESS == taskInfo.getExecuteResultCode()) {
                    CompileData compileData = taskInfo.getCompileData();
                    System.out.println(taskId + " compile success,url is " + compileData.getUrl());
                } else {
                    System.out.println(taskId + " compile error,msg is " + taskInfo.getExecuteResultMsg());
                }
                break;
            } else if (TaskStateEnum.WORK.name().equalsIgnoreCase(taskInfo.getExecuteState())) {
                System.out.println(taskId + " compile progress  " + taskInfo.getTaskProgress());
            }
        }
        System.exit(0);

    }
}