main
HuangHai 3 months ago
parent 16eb444c87
commit 78ffb0fd0b

@ -2,6 +2,7 @@ package com.dsideal.aiSupport.Util.JiMeng;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.jfinal.kit.StrKit;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -30,23 +31,29 @@ public class JmText2Video extends JmCommon {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
String prompt = "蓝色毛绒玩具在超市里拖地,结果拖把洒出好多五颜六色的粉末,接着把粉末洒向镜头前,镜头随之穿过粉末"; String prompt = "蓝色毛绒玩具在超市里拖地,结果拖把洒出好多五颜六色的粉末,接着把粉末洒向镜头前,镜头随之穿过粉末";
JSONObject jo = JmText2Video.generateVideo(prompt); JSONObject jo = JmText2Video.generateVideo(prompt);
log.info("结果:{}", jo);
String taskId = jo.getJSONObject("data").getString("task_id"); String taskId = jo.getJSONObject("data").getString("task_id");
//检查任务是不是已经结束 //检查任务是不是已经结束
while (true) { while (true) {
JSONObject result = JmCommon.queryTaskResult(taskId); JSONObject result = JmCommon.queryTaskResult(taskId);
log.info("查询结果:{}", result);
if (result.getInteger("code") != 10000) { if (result.getInteger("code") != 10000) {
log.error("查询失败,错误代码=" + result.getInteger("code")); log.error("查询失败,错误代码=" + result.getInteger("code"));
break; break;
} }
JSONObject data = result.getJSONObject("data"); JSONObject data = result.getJSONObject("data");
String status = data.getString("status");
if (status.equals("done")) { if (!StrKit.isBlank(data.getString("video_url"))) {
String video_url = data.getString("video_url"); String video_url = data.getString("video_url");
log.info("视频地址:{}", video_url); log.info("视频地址:{}", video_url);
break; break;
} else { } else {
log.info("任务处理中..."); if (data.getString("status").equals("in_queue")) {
Thread.sleep(5000); log.info("任务排队中...");
} else {
log.info("任务已经开始处理");
}
Thread.sleep(3000);
} }
} }
} }

Loading…
Cancel
Save