diff --git a/common/src/main/java/ctbrec/recorder/download/dash/DashDownload.java b/common/src/main/java/ctbrec/recorder/download/dash/DashDownload.java index 54f0c770..46c14cbd 100644 --- a/common/src/main/java/ctbrec/recorder/download/dash/DashDownload.java +++ b/common/src/main/java/ctbrec/recorder/download/dash/DashDownload.java @@ -137,21 +137,29 @@ public class DashDownload implements Download { String initialization = segmentTemplate.getInitializationAttribute(); initialization = initialization.replaceAll("\\$RepresentationID\\$", representation.getId()); URL initUrl = new URL(new URL(mpd.getLocation().get(0)), initialization); - download(downloadDir.toFile().getCanonicalPath(), initUrl, isVideo); - if (isVideo) { - LOG.debug("Video init chunk loaded"); - videoInitLoaded = true; - } else { - LOG.debug("Audio init chunk loaded"); - audioInitLoaded = true; - } + File file = download(downloadDir.toFile().getCanonicalPath(), initUrl, isVideo); + setInitState(isVideo, file); return 1; } else { return 0; } } - private void download(String dir, URL url, boolean isVideo) throws IOException { + private void setInitState(boolean isVideo, File file) { + if (isVideo) { + if (file.exists() && file.length() > 0) { + LOG.debug("Video init chunk loaded"); + videoInitLoaded = true; + } + } else { + if (file.exists() && file.length() > 0) { + LOG.debug("Audio init chunk loaded"); + audioInitLoaded = true; + } + } + } + + private File download(String dir, URL url, boolean isVideo) throws IOException { // @formatter:off Request request = new Request.Builder() .url(url) @@ -189,6 +197,7 @@ public class DashDownload implements Download { } tries++; } + return segmentFile; } }