Do not mux video and audio on Android 7 and below.

This commit is contained in:
Docile-Alligator 2022-06-27 17:55:22 +08:00
parent 42a935981d
commit 974730db1a

View File

@ -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,6 +222,7 @@ public class DownloadRedditVideoService extends Service {
return;
}
if (audioUrl != null) {
Response<ResponseBody> audioResponse = downloadFile.downloadFile(audioUrl).execute();
if (audioResponse.isSuccessful() && audioResponse.body() != null) {
String audioFilePath = externalCacheDirectoryPath + fileNameWithoutExtension + "-cache.mp3";
@ -265,6 +267,18 @@ public class DownloadRedditVideoService extends Service {
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 {
downloadFinished(null, ERROR_VIDEO_FILE_CANNOT_DOWNLOAD, randomNotificationIdOffset);
}
@ -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();