From b7b9a7f3bd0c7c7d5dd3ed86db7c0929defb1ba6 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Tue, 2 Feb 2021 22:47:18 +0800 Subject: Fix downloading videos without sound failed. --- .../services/DownloadRedditVideoService.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java index 73839464..f1b9633e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java @@ -25,6 +25,7 @@ import android.os.Looper; import android.os.Message; import android.os.Process; import android.provider.MediaStore; +import android.util.Log; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; @@ -207,17 +208,18 @@ public class DownloadRedditVideoService extends Service { updateNotification(R.string.downloading_reddit_video_audio_track, 0, randomNotificationIdOffset, null); + String videoFilePath = externalCacheDirectoryPath + fileNameWithoutExtension + "-cache.mp4"; + String savedVideoFilePath = writeResponseBodyToDisk(videoResponse.body(), videoFilePath); + if (savedVideoFilePath == null) { + downloadFinished(null, ERROR_VIDEO_FILE_CANNOT_SAVE, randomNotificationIdOffset); + return; + } + Response audioResponse = downloadFile.downloadFile(audioUrl).execute(); if (audioResponse.isSuccessful() && audioResponse.body() != null) { - String videoFilePath = externalCacheDirectoryPath + fileNameWithoutExtension + "-cache.mp4"; String audioFilePath = externalCacheDirectoryPath + fileNameWithoutExtension + "-cache.mp3"; String outputFilePath = externalCacheDirectoryPath + fileNameWithoutExtension + ".mp4"; - String savedVideoFilePath = writeResponseBodyToDisk(videoResponse.body(), videoFilePath); - if (savedVideoFilePath == null) { - downloadFinished(null, ERROR_VIDEO_FILE_CANNOT_SAVE, randomNotificationIdOffset); - return; - } String savedAudioFilePath = writeResponseBodyToDisk(audioResponse.body(), audioFilePath); if (savedAudioFilePath == null) { downloadFinished(null, ERROR_AUDIO_FILE_CANNOT_SAVE, randomNotificationIdOffset); @@ -246,8 +248,6 @@ public class DownloadRedditVideoService extends Service { downloadFinished(null, ERROR_MUXED_VIDEO_FILE_CANNOT_SAVE, randomNotificationIdOffset); } } else { - String videoFilePath = externalCacheDirectoryPath + fileNameWithoutExtension + "-cache.mp4"; - updateNotification(R.string.downloading_reddit_video_save_file_to_public_dir, -1, randomNotificationIdOffset, null); try { -- cgit v1.2.3