Browse Source

feat: tool 生成失败提示

hexleo 5 years ago
parent
commit
98ab801440

+ 40 - 17
Android/PlayerProj/animtool/src/main/java/com/tencent/qgame/playerproj/animtool/AnimTool.java

@@ -57,13 +57,14 @@ public class AnimTool {
      */
      */
     public void create(final CommonArg commonArg, final boolean needVideo) throws Exception{
     public void create(final CommonArg commonArg, final boolean needVideo) throws Exception{
         TLog.i(TAG, "start create");
         TLog.i(TAG, "start create");
-        createAllFrameImage(commonArg, new Runnable() {
+        createAllFrameImage(commonArg, new IRunResult() {
             @Override
             @Override
-            public void run() {
+            public boolean run() {
                 if (finalCheck(commonArg) && needVideo) {
                 if (finalCheck(commonArg) && needVideo) {
                     // 最终生成视频文件
                     // 最终生成视频文件
-                    createVideo(commonArg);
+                    return createVideo(commonArg);
                 }
                 }
+                return false;
             }
             }
         });
         });
     }
     }
@@ -93,7 +94,7 @@ public class AnimTool {
         return true;
         return true;
     }
     }
 
 
-    private void createAllFrameImage(final CommonArg commonArg, final Runnable finishRunnable) throws Exception{
+    private void createAllFrameImage(final CommonArg commonArg, final IRunResult finishRunnable) throws Exception{
         if (!checkCommonArg(commonArg)) {
         if (!checkCommonArg(commonArg)) {
             if (toolListener != null) toolListener.onError();
             if (toolListener != null) toolListener.onError();
             return;
             return;
@@ -147,13 +148,18 @@ public class AnimTool {
                     synchronized (AnimTool.class) {
                     synchronized (AnimTool.class) {
                         finishThreadCount++;
                         finishThreadCount++;
                         if (finishThreadCount == threadNum) {
                         if (finishThreadCount == threadNum) {
+                            boolean result = false;
                             if (finishRunnable != null) {
                             if (finishRunnable != null) {
-                                finishRunnable.run();
+                                result = finishRunnable.run();
                             }
                             }
                             long cost = System.currentTimeMillis() - time;
                             long cost = System.currentTimeMillis() - time;
                             TLog.i(TAG,"Finish cost=" + cost);
                             TLog.i(TAG,"Finish cost=" + cost);
                             if (toolListener != null) {
                             if (toolListener != null) {
-                                toolListener.onComplete();
+                                if (result) {
+                                    toolListener.onComplete();
+                                } else {
+                                    toolListener.onError();
+                                }
                             }
                             }
                         }
                         }
                     }
                     }
@@ -195,7 +201,7 @@ public class AnimTool {
      * 创建最终的视频
      * 创建最终的视频
      * @param commonArg
      * @param commonArg
      */
      */
-    private void createVideo(CommonArg commonArg){
+    private boolean createVideo(CommonArg commonArg) {
         try {
         try {
             // 创建配置json文件
             // 创建配置json文件
             createVapcJson(commonArg);
             createVapcJson(commonArg);
@@ -203,14 +209,16 @@ public class AnimTool {
             boolean result = createMp4(commonArg, commonArg.outputPath, commonArg.frameOutputPath);
             boolean result = createMp4(commonArg, commonArg.outputPath, commonArg.frameOutputPath);
             if (!result) {
             if (!result) {
                 TLog.i(TAG, "createMp4 fail");
                 TLog.i(TAG, "createMp4 fail");
-                return;
+                deleteFile(commonArg);
+                return false;
             }
             }
             String tempVideoName = TEMP_VIDEO_FILE;
             String tempVideoName = TEMP_VIDEO_FILE;
             if (commonArg.needAudio) {
             if (commonArg.needAudio) {
                 result = mergeAudio2Mp4(commonArg, tempVideoName);
                 result = mergeAudio2Mp4(commonArg, tempVideoName);
                 if (!result) {
                 if (!result) {
                     TLog.i(TAG, "mergeAudio2Mp4 fail");
                     TLog.i(TAG, "mergeAudio2Mp4 fail");
-                    return;
+                    deleteFile(commonArg);
+                    return false;
                 }
                 }
                 tempVideoName = TEMP_VIDEO_AUDIO_FILE;
                 tempVideoName = TEMP_VIDEO_AUDIO_FILE;
             }
             }
@@ -222,20 +230,31 @@ public class AnimTool {
             result = mergeBin2Mp4(commonArg, vapcBinPath, tempVideoName, commonArg.outputPath);
             result = mergeBin2Mp4(commonArg, vapcBinPath, tempVideoName, commonArg.outputPath);
             if (!result) {
             if (!result) {
                 TLog.i(TAG, "mergeBin2Mp4 fail");
                 TLog.i(TAG, "mergeBin2Mp4 fail");
-                return;
-            }
-            // 删除临时视频文件
-            new File(commonArg.outputPath + TEMP_VIDEO_FILE).delete();
-            if (commonArg.needAudio) {
-                new File(commonArg.outputPath + TEMP_VIDEO_AUDIO_FILE).delete();
+                deleteFile(commonArg);
+                return false;
             }
             }
-            new File(commonArg.outputPath + VAPC_BIN_FILE).delete();
+            deleteFile(commonArg);
             // 计算文件md5
             // 计算文件md5
             String md5 = new Md5Util().getFileMD5(new File(commonArg.outputPath + VIDEO_FILE), commonArg.outputPath);
             String md5 = new Md5Util().getFileMD5(new File(commonArg.outputPath + VIDEO_FILE), commonArg.outputPath);
             TLog.i(TAG, "md5="+md5);
             TLog.i(TAG, "md5="+md5);
         } catch (Exception e) {
         } catch (Exception e) {
-            e.printStackTrace();
+            TLog.e(TAG, "createVideo error:" + e.getMessage());
+            return false;
         }
         }
+        return true;
+    }
+
+    private void deleteFile(CommonArg commonArg) {
+        // 删除临时视频文件
+        File file;
+        file = new File(commonArg.outputPath + TEMP_VIDEO_FILE);
+        if (file.exists()) file.delete();
+        if (commonArg.needAudio) {
+            file = new File(commonArg.outputPath + TEMP_VIDEO_AUDIO_FILE);
+            if (file.exists()) file.delete();
+        }
+        file = new File(commonArg.outputPath + VAPC_BIN_FILE);
+        if (file.exists()) file.delete();
     }
     }
 
 
     /**
     /**
@@ -366,4 +385,8 @@ public class AnimTool {
         void onComplete();
         void onComplete();
     }
     }
 
 
+    private interface IRunResult {
+        boolean run();
+    }
+
 }
 }

+ 2 - 1
Android/PlayerProj/animtool/src/main/java/com/tencent/qgame/playerproj/animtool/Md5Util.java

@@ -24,6 +24,7 @@ import java.io.InputStream;
 import java.security.MessageDigest;
 import java.security.MessageDigest;
 
 
 public class Md5Util {
 public class Md5Util {
+    public static final String MD5_FILE = "md5.txt";
     private char[] hexDigits = new char[] {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
     private char[] hexDigits = new char[] {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
 
 
 
 
@@ -48,7 +49,7 @@ public class Md5Util {
                 md5txt = bufferToHex(digest);
                 md5txt = bufferToHex(digest);
             }
             }
             try {
             try {
-                BufferedWriter writer = new BufferedWriter(new FileWriter(outputPath + "/md5.txt"));
+                BufferedWriter writer = new BufferedWriter(new FileWriter(outputPath + MD5_FILE));
                 writer.write(md5txt);
                 writer.write(md5txt);
                 writer.flush();
                 writer.flush();
                 writer.close();
                 writer.close();

+ 19 - 15
Android/PlayerProj/animtool/src/main/java/com/tencent/qgame/playerproj/animtool/ui/ToolUI.java

@@ -126,7 +126,7 @@ public class ToolUI {
                     runAnimTool();
                     runAnimTool();
                 } catch (Exception e) {
                 } catch (Exception e) {
                     TLog.e(TAG, e.getMessage());
                     TLog.e(TAG, e.getMessage());
-                    btnCreate.setEnabled(true);
+                    setOutput(false, "");
                 }
                 }
             }
             }
         }).start();
         }).start();
@@ -187,13 +187,12 @@ public class ToolUI {
 
 
             @Override
             @Override
             public void onError() {
             public void onError() {
-                btnCreate.setEnabled(true);
+                setOutput(false, "");
             }
             }
 
 
             @Override
             @Override
             public void onComplete() {
             public void onComplete() {
-                btnCreate.setEnabled(true);
-                setOutput(commonArg.outputPath);
+                setOutput(true, commonArg.outputPath);
                 try {
                 try {
                     setProperties(commonArg);
                     setProperties(commonArg);
                     Desktop.getDesktop().open(new File(commonArg.outputPath));
                     Desktop.getDesktop().open(new File(commonArg.outputPath));
@@ -390,18 +389,23 @@ public class ToolUI {
         return panel;
         return panel;
     }
     }
 
 
-    private void setOutput(final String path) {
-        labelOutInfo.setText("<html><font color='blue'>open output</font></html>");
-        labelOutInfo.addMouseListener(new MouseAdapter() {
-            @Override
-            public void mouseClicked(MouseEvent mouseEvent) {
-                try {
-                    Desktop.getDesktop().open(new File(path));
-                } catch (IOException e) {
-                    TLog.e(TAG, e.getMessage());
+    private void setOutput(boolean success, final String path) {
+        btnCreate.setEnabled(true);
+        if (success) {
+            labelOutInfo.setText("<html><font color='blue'>open output</font></html>");
+            labelOutInfo.addMouseListener(new MouseAdapter() {
+                @Override
+                public void mouseClicked(MouseEvent mouseEvent) {
+                    try {
+                        Desktop.getDesktop().open(new File(path));
+                    } catch (IOException e) {
+                        TLog.e(TAG, e.getMessage());
+                    }
                 }
                 }
-            }
-        });
+            });
+        } else {
+            labelOutInfo.setText("<html><font color='red'>create error!</font></html>");
+        }
     }
     }