From 0c0a67bb9321c951ed202a6d82905ae9deb99dd5 Mon Sep 17 00:00:00 2001 From: bachinger Date: Thu, 17 Oct 2019 18:56:39 +0100 Subject: [PATCH] Fail at preparation when trying to download live content. PiperOrigin-RevId: 275293735 --- .../android/exoplayer2/demo/DownloadTracker.java | 7 ++++++- .../android/exoplayer2/offline/DownloadHelper.java | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/demos/main/src/main/java/com/google/android/exoplayer2/demo/DownloadTracker.java b/demos/main/src/main/java/com/google/android/exoplayer2/demo/DownloadTracker.java index 440a25a289..143eda93df 100644 --- a/demos/main/src/main/java/com/google/android/exoplayer2/demo/DownloadTracker.java +++ b/demos/main/src/main/java/com/google/android/exoplayer2/demo/DownloadTracker.java @@ -216,7 +216,12 @@ public class DownloadTracker { @Override public void onPrepareError(DownloadHelper helper, IOException e) { Toast.makeText(context, R.string.download_start_error, Toast.LENGTH_LONG).show(); - Log.e(TAG, "Failed to start download", e); + Log.e( + TAG, + e instanceof DownloadHelper.LiveContentUnsupportedException + ? "Downloading live content unsupported" + : "Failed to start download", + e); } // DialogInterface.OnClickListener implementation. diff --git a/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadHelper.java b/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadHelper.java index 57ef5731fb..2e64d9f421 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadHelper.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadHelper.java @@ -137,6 +137,9 @@ public final class DownloadHelper { void onPrepareError(DownloadHelper helper, IOException e); } + /** Thrown at an attempt to download live content. */ + public static class LiveContentUnsupportedException extends IOException {} + @Nullable private static final Constructor DASH_FACTORY_CONSTRUCTOR = getConstructor("com.google.android.exoplayer2.source.dash.DashMediaSource$Factory"); @@ -999,6 +1002,14 @@ public final class DownloadHelper { // Ignore dynamic updates. return; } + if (timeline.getWindow(/* windowIndex= */ 0, new Timeline.Window()).isLive) { + downloadHelperHandler + .obtainMessage( + DOWNLOAD_HELPER_CALLBACK_MESSAGE_FAILED, + /* obj= */ new LiveContentUnsupportedException()) + .sendToTarget(); + return; + } this.timeline = timeline; mediaPeriods = new MediaPeriod[timeline.getPeriodCount()]; for (int i = 0; i < mediaPeriods.length; i++) {