diff options
author | Docile-Alligator <chineseperson5@gmail.com> | 2022-06-27 09:55:22 +0000 |
---|---|---|
committer | Docile-Alligator <chineseperson5@gmail.com> | 2022-06-27 09:55:22 +0000 |
commit | 974730db1a6769bb34db54789d7818acf85a3edc (patch) | |
tree | 8c1d725d2c9c2244d14c4967b0d55a6abeead1d4 /app/src/main/java/ml | |
parent | 42a935981dd4b6fe33b4a16d58418f273d45fce2 (diff) | |
download | infinity-for-reddit-974730db1a6769bb34db54789d7818acf85a3edc.tar infinity-for-reddit-974730db1a6769bb34db54789d7818acf85a3edc.tar.gz infinity-for-reddit-974730db1a6769bb34db54789d7818acf85a3edc.tar.bz2 infinity-for-reddit-974730db1a6769bb34db54789d7818acf85a3edc.tar.lz infinity-for-reddit-974730db1a6769bb34db54789d7818acf85a3edc.tar.xz infinity-for-reddit-974730db1a6769bb34db54789d7818acf85a3edc.tar.zst infinity-for-reddit-974730db1a6769bb34db54789d7818acf85a3edc.zip |
Do not mux video and audio on Android 7 and below.
Diffstat (limited to 'app/src/main/java/ml')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java | 69 |
1 files changed, 42 insertions, 27 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 3f49d6c7..ba44b1ab 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.NotificationChannelCompat; import androidx.core.app.NotificationCompat; @@ -98,7 +99,7 @@ public class DownloadRedditVideoService extends Service { public void handleMessage(Message msg) { Bundle intent = msg.getData(); String videoUrl = intent.getString(EXTRA_VIDEO_URL); - String audioUrl = videoUrl.substring(0, videoUrl.lastIndexOf('/')) + "/DASH_audio.mp4"; + String audioUrl = Build.VERSION.SDK_INT > Build.VERSION_CODES.N ? videoUrl.substring(0, videoUrl.lastIndexOf('/')) + "/DASH_audio.mp4" : null; String subredditName = intent.getString(EXTRA_SUBREDDIT); String fileNameWithoutExtension = subredditName + "-" + intent.getString(EXTRA_POST_ID); boolean isNsfw = intent.getBoolean(EXTRA_IS_NSFW, false); @@ -221,37 +222,50 @@ public class DownloadRedditVideoService extends Service { return; } - Response<ResponseBody> audioResponse = downloadFile.downloadFile(audioUrl).execute(); - if (audioResponse.isSuccessful() && audioResponse.body() != null) { - String audioFilePath = externalCacheDirectoryPath + fileNameWithoutExtension + "-cache.mp3"; - String outputFilePath = externalCacheDirectoryPath + fileNameWithoutExtension + ".mp4"; + if (audioUrl != null) { + Response<ResponseBody> audioResponse = downloadFile.downloadFile(audioUrl).execute(); + if (audioResponse.isSuccessful() && audioResponse.body() != null) { + String audioFilePath = externalCacheDirectoryPath + fileNameWithoutExtension + "-cache.mp3"; + String outputFilePath = externalCacheDirectoryPath + fileNameWithoutExtension + ".mp4"; - String savedAudioFilePath = writeResponseBodyToDisk(audioResponse.body(), audioFilePath); - if (savedAudioFilePath == null) { - downloadFinished(null, ERROR_AUDIO_FILE_CANNOT_SAVE, randomNotificationIdOffset); - return; - } + String savedAudioFilePath = writeResponseBodyToDisk(audioResponse.body(), audioFilePath); + if (savedAudioFilePath == null) { + downloadFinished(null, ERROR_AUDIO_FILE_CANNOT_SAVE, randomNotificationIdOffset); + return; + } - updateNotification(R.string.downloading_reddit_video_muxing, -1, - randomNotificationIdOffset, null); - if (!muxVideoAndAudio(videoFilePath, audioFilePath, outputFilePath)) { - downloadFinished(null, ERROR_MUX_FAILED, randomNotificationIdOffset); - return; - } + updateNotification(R.string.downloading_reddit_video_muxing, -1, + randomNotificationIdOffset, null); + if (!muxVideoAndAudio(videoFilePath, audioFilePath, outputFilePath)) { + downloadFinished(null, ERROR_MUX_FAILED, randomNotificationIdOffset); + return; + } - updateNotification(R.string.downloading_reddit_video_save_file_to_public_dir, -1, - randomNotificationIdOffset, null); - try { - Uri destinationFileUri = copyToDestination(outputFilePath, destinationFileUriString, destinationFileName, isDefaultDestination); + updateNotification(R.string.downloading_reddit_video_save_file_to_public_dir, -1, + randomNotificationIdOffset, null); + try { + Uri destinationFileUri = copyToDestination(outputFilePath, destinationFileUriString, destinationFileName, isDefaultDestination); - new File(videoFilePath).delete(); - new File(audioFilePath).delete(); - new File(outputFilePath).delete(); + new File(videoFilePath).delete(); + new File(audioFilePath).delete(); + new File(outputFilePath).delete(); - downloadFinished(destinationFileUri, NO_ERROR, randomNotificationIdOffset); - } catch (IOException e) { - e.printStackTrace(); - downloadFinished(null, ERROR_MUXED_VIDEO_FILE_CANNOT_SAVE, randomNotificationIdOffset); + downloadFinished(destinationFileUri, NO_ERROR, randomNotificationIdOffset); + } catch (IOException e) { + e.printStackTrace(); + downloadFinished(null, ERROR_MUXED_VIDEO_FILE_CANNOT_SAVE, randomNotificationIdOffset); + } + } else { + updateNotification(R.string.downloading_reddit_video_save_file_to_public_dir, -1, + randomNotificationIdOffset, null); + try { + Uri destinationFileUri = copyToDestination(videoFilePath, destinationFileUriString, destinationFileName, isDefaultDestination); + new File(videoFilePath).delete(); + downloadFinished(destinationFileUri, NO_ERROR, randomNotificationIdOffset); + } catch (IOException e) { + e.printStackTrace(); + downloadFinished(null, ERROR_MUXED_VIDEO_FILE_CANNOT_SAVE, randomNotificationIdOffset); + } } } else { updateNotification(R.string.downloading_reddit_video_save_file_to_public_dir, -1, @@ -325,6 +339,7 @@ public class DownloadRedditVideoService extends Service { } private boolean muxVideoAndAudio(String videoFilePath, String audioFilePath, String outputFilePath) { + Log.i("asdfasdf", "sasdfasdf"); try { File file = new File(outputFilePath); file.createNewFile(); |