Browse Source

修改云教练部分问题

Pq 2 years ago
parent
commit
edcbda07ea

+ 4 - 0
ffmpegCmd/build.gradle

@@ -30,6 +30,10 @@ android {
             minifyEnabled false
             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
         }
+        preRelease{
+            minifyEnabled false
+            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+        }
     }
     compileOptions {
         sourceCompatibility JavaVersion.VERSION_1_8

+ 17 - 7
student/src/main/java/com/cooleshow/student/helper/AccompanyHelper.java

@@ -9,6 +9,7 @@ import com.cooleshow.base.data.api.DownloadApi;
 import com.cooleshow.base.data.net.RetrofitClientNoToken;
 import com.cooleshow.base.data.net.RetrofitFactory;
 import com.cooleshow.base.utils.FileUtils;
+import com.cooleshow.base.utils.LogUtils;
 import com.cooleshow.base.utils.Utils;
 import com.cooleshow.ffmpegcmd.FFmpegCmd;
 import com.cooleshow.ffmpegcmd.util.FFmpegUtil;
@@ -43,7 +44,7 @@ public class AccompanyHelper {
     public static final String videoMp3Path = BASE_PATH + File.separator + "videoBgm.mp3";
     public static final String mergeMp3Path = BASE_PATH + File.separator + "merge.mp3";
     public static final String onlyVideoPath = BASE_PATH + File.separator + "onlyVideoPath.mp4";
-    public static final String resultPathPath = BASE_PATH + File.separator + "result.mp4";
+    public static String resultPathPath = BASE_PATH + File.separator + "result.mp4";
 
     private AccompanyHelper() {
 
@@ -64,7 +65,7 @@ public class AccompanyHelper {
         Observable.create(new ObservableOnSubscribe<String>() {
             @Override
             public void subscribe(@NonNull ObservableEmitter<String> emitter) throws Throwable {
-                FileUtils.delete(accompanimentMp3Path);
+                deleteAllTempFile();
                 FileUtils.createOrExistsFile(accompanimentMp3Path);
                 File file = new File(accompanimentMp3Path);
                 downloadAccompany(url, file);
@@ -136,7 +137,6 @@ public class AccompanyHelper {
         Observable.create(new ObservableOnSubscribe<String>() {
             @Override
             public void subscribe(@NonNull ObservableEmitter<String> emitter) throws Throwable {
-                deleteAllTempFile();
                 Log.i(TAG, "转换开始");
                 int getVideoMp3Result = getVideoMp3_2(videoPath, videoMp3Path);
                 Log.i(TAG, "getVideoMp3 complete:" + getVideoMp3Result);
@@ -148,6 +148,7 @@ public class AccompanyHelper {
                 int getOnlyVideoResult = getOnlyVideo(videoPath, onlyVideoPath);
                 Log.i(TAG, "extractVideo complete:" + getOnlyVideoResult);
                 //merge音频和视频
+                resultPathPath = getLastResultPath();
                 int mergeResult = megreMp3AndMp4(onlyVideoPath, mergeMp3Path, resultPathPath);
                 Log.i(TAG, "mergeMp4 complete:" + mergeResult);
                 Log.i(TAG, "转换完成");
@@ -191,11 +192,20 @@ public class AccompanyHelper {
                 });
     }
 
+    private String getLastResultPath() {
+        String timeStamp = String.valueOf(System.currentTimeMillis());
+        String lastPath = BASE_PATH + File.separator + "VIDEO_RESULT_" + timeStamp + ".mp4";
+        LogUtils.i(TAG,"lastPath:"+lastPath);
+        return lastPath;
+    }
+
     private void deleteAllTempFile() {
-        FileUtils.delete(videoMp3Path);
-        FileUtils.delete(mergeMp3Path);
-        FileUtils.delete(onlyVideoPath);
-        FileUtils.delete(resultPathPath);
+        boolean b = FileUtils.deleteAllInDir(BASE_PATH);
+        LogUtils.i(TAG, "deleteAllTempFile:" + b);
+//        FileUtils.delete(videoMp3Path);
+//        FileUtils.delete(mergeMp3Path);
+//        FileUtils.delete(onlyVideoPath);
+//        FileUtils.delete(resultPathPath);
     }
 
     public int getVideoMp3_2(String videoPath, String outPath) {

+ 8 - 1
student/src/main/java/com/cooleshow/student/ui/web/AccompanyActivity.java

@@ -163,6 +163,9 @@ public class AccompanyActivity extends BaseMVPActivity<ActivityAccompanyBinding,
                         @Override
                         public void onVideo(CameraKitVideo cameraKitVideo) {
                             try {
+                                if (!checkActivityExist()) {
+                                    return;
+                                }
                                 File file = cameraKitVideo.getVideoFile();
                                 filePath = file.getPath();
                                 if (!TextUtils.isEmpty(accompanimentUrl)) {
@@ -259,8 +262,12 @@ public class AccompanyActivity extends BaseMVPActivity<ActivityAccompanyBinding,
              */
             @Override
             public void endCapture() {
-                showLoading("正在处理视频中");
+                if (!checkActivityExist()) {
+                    FileUtils.delete(recordVideFilePath);
+                    return;
+                }
                 if (cameraView != null && cameraView.getVisibility() == View.VISIBLE) {
+                    showLoading("正在处理视频中");
                     new Handler().postDelayed(new Runnable() {
                         @Override
                         public void run() {

+ 3 - 0
student/src/main/java/com/cooleshow/student/ui/web/AccompanyFragment.java

@@ -319,6 +319,9 @@ public class AccompanyFragment extends BaseMVPFragment<FragmentAccompanyBinding,
     @Override
     public void onSendMessage(String message) {
         Log.i("accom", "message:" + message);
+        if (isDetached()) {
+            return;
+        }
         if (webView != null) {
             webView.evaluateJavascript("postMessage('" + message + "')", new ValueCallback<String>() {
                 @Override

+ 13 - 7
teacher/src/main/java/com/cooleshow/teacher/helper/AccompanyHelper.java

@@ -7,6 +7,7 @@ import com.cooleshow.base.callback.ResultCallback;
 import com.cooleshow.base.data.api.DownloadApi;
 import com.cooleshow.base.data.net.RetrofitClientNoToken;
 import com.cooleshow.base.utils.FileUtils;
+import com.cooleshow.base.utils.LogUtils;
 import com.cooleshow.base.utils.Utils;
 import com.cooleshow.ffmpegcmd.FFmpegCmd;
 import com.cooleshow.ffmpegcmd.util.FFmpegUtil;
@@ -38,7 +39,7 @@ public class AccompanyHelper {
     public static final String videoMp3Path = BASE_PATH + File.separator + "videoBgm.mp3";
     public static final String mergeMp3Path = BASE_PATH + File.separator + "merge.mp3";
     public static final String onlyVideoPath = BASE_PATH + File.separator + "onlyVideoPath.mp4";
-    public static final String resultPathPath = BASE_PATH + File.separator + "result.mp4";
+    public static String resultPathPath = BASE_PATH + File.separator + "result.mp4";
 
     private AccompanyHelper() {
 
@@ -59,7 +60,7 @@ public class AccompanyHelper {
         Observable.create(new ObservableOnSubscribe<String>() {
             @Override
             public void subscribe(@NonNull ObservableEmitter<String> emitter) throws Throwable {
-                FileUtils.delete(accompanimentMp3Path);
+                deleteAllTempFile();
                 FileUtils.createOrExistsFile(accompanimentMp3Path);
                 File file = new File(accompanimentMp3Path);
                 downloadAccompany(url, file);
@@ -131,7 +132,6 @@ public class AccompanyHelper {
         Observable.create(new ObservableOnSubscribe<String>() {
             @Override
             public void subscribe(@NonNull ObservableEmitter<String> emitter) throws Throwable {
-                deleteAllTempFile();
                 Log.i(TAG, "转换开始");
                 int getVideoMp3Result = getVideoMp3_2(videoPath, videoMp3Path);
                 Log.i(TAG, "getVideoMp3 complete:" + getVideoMp3Result);
@@ -143,6 +143,7 @@ public class AccompanyHelper {
                 int getOnlyVideoResult = getOnlyVideo(videoPath, onlyVideoPath);
                 Log.i(TAG, "extractVideo complete:" + getOnlyVideoResult);
                 //merge音频和视频
+                resultPathPath = getLastResultPath();
                 int mergeResult = megreMp3AndMp4(onlyVideoPath, mergeMp3Path, resultPathPath);
                 Log.i(TAG, "mergeMp4 complete:" + mergeResult);
                 Log.i(TAG, "转换完成");
@@ -186,11 +187,16 @@ public class AccompanyHelper {
                 });
     }
 
+    private String getLastResultPath() {
+        String timeStamp = String.valueOf(System.currentTimeMillis());
+        String lastPath = BASE_PATH + File.separator + "VIDEO_RESULT_" + timeStamp + ".mp4";
+        LogUtils.i(TAG,"lastPath:"+lastPath);
+        return lastPath;
+    }
+
     private void deleteAllTempFile() {
-        FileUtils.delete(videoMp3Path);
-        FileUtils.delete(mergeMp3Path);
-        FileUtils.delete(onlyVideoPath);
-        FileUtils.delete(resultPathPath);
+        boolean b = FileUtils.deleteAllInDir(BASE_PATH);
+        LogUtils.i(TAG, "deleteAllTempFile:" + b);
     }
 
     public int getVideoMp3_2(String videoPath, String outPath) {

+ 7 - 0
teacher/src/main/java/com/cooleshow/teacher/ui/web/AccompanyActivity.java

@@ -164,6 +164,9 @@ public class AccompanyActivity extends BaseMVPActivity<ActivityAccompanyBinding,
                         @Override
                         public void onVideo(CameraKitVideo cameraKitVideo) {
                             try {
+                                if (!checkActivityExist()) {
+                                    return;
+                                }
                                 File file = cameraKitVideo.getVideoFile();
                                 filePath = file.getPath();
                                 if (!TextUtils.isEmpty(accompanimentUrl)) {
@@ -261,6 +264,10 @@ public class AccompanyActivity extends BaseMVPActivity<ActivityAccompanyBinding,
              */
             @Override
             public void endCapture() {
+                if (!checkActivityExist()) {
+                    FileUtils.delete(recordVideFilePath);
+                    return;
+                }
                 if (cameraView != null && cameraView.getVisibility() == View.VISIBLE) {
                     showLoading("正在处理视频中");
                     new Handler().postDelayed(new Runnable() {

+ 3 - 0
teacher/src/main/java/com/cooleshow/teacher/ui/web/AccompanyFragment.java

@@ -328,6 +328,9 @@ public class AccompanyFragment extends BaseMVPFragment<FragmentAccompanyBinding,
     @Override
     public void onSendMessage(String message) {
         Log.i("acc","message:"+message);
+        if (isDetached()) {
+            return;
+        }
         if (webView != null) {
             webView.evaluateJavascript("postMessage('" + message + "')", new ValueCallback<String>() {
                 @Override