Commit c1993689 by christosts Committed by Ian Baker

DownloadHelper: propagate errors to callback

When downlading an adaptive asset, if an ExoPlaybackException happens
during track selection, the player raises an
UnsupportedOperationException which is not handled gracefully and can
crash the app main thread.

This change catches the error and forwards it to
DownloadHelper.Callback.onPrepareError() as an IOException.

PiperOrigin-RevId: 443015332
parent eb72e0aa
...@@ -619,9 +619,13 @@ public final class DownloadHelper { ...@@ -619,9 +619,13 @@ public final class DownloadHelper {
*/ */
public void replaceTrackSelections( public void replaceTrackSelections(
int periodIndex, TrackSelectionParameters trackSelectionParameters) { int periodIndex, TrackSelectionParameters trackSelectionParameters) {
try {
assertPreparedWithMedia(); assertPreparedWithMedia();
clearTrackSelections(periodIndex); clearTrackSelections(periodIndex);
addTrackSelectionInternal(periodIndex, trackSelectionParameters); addTrackSelectionInternal(periodIndex, trackSelectionParameters);
} catch (ExoPlaybackException e) {
throw new IllegalStateException(e);
}
} }
/** /**
...@@ -634,8 +638,12 @@ public final class DownloadHelper { ...@@ -634,8 +638,12 @@ public final class DownloadHelper {
*/ */
public void addTrackSelection( public void addTrackSelection(
int periodIndex, TrackSelectionParameters trackSelectionParameters) { int periodIndex, TrackSelectionParameters trackSelectionParameters) {
try {
assertPreparedWithMedia(); assertPreparedWithMedia();
addTrackSelectionInternal(periodIndex, trackSelectionParameters); addTrackSelectionInternal(periodIndex, trackSelectionParameters);
} catch (ExoPlaybackException e) {
throw new IllegalStateException(e);
}
} }
/** /**
...@@ -647,6 +655,7 @@ public final class DownloadHelper { ...@@ -647,6 +655,7 @@ public final class DownloadHelper {
* selection, as IETF BCP 47 conformant tags. * selection, as IETF BCP 47 conformant tags.
*/ */
public void addAudioLanguagesToSelection(String... languages) { public void addAudioLanguagesToSelection(String... languages) {
try {
assertPreparedWithMedia(); assertPreparedWithMedia();
TrackSelectionParameters.Builder parametersBuilder = TrackSelectionParameters.Builder parametersBuilder =
...@@ -669,6 +678,9 @@ public final class DownloadHelper { ...@@ -669,6 +678,9 @@ public final class DownloadHelper {
addTrackSelectionInternal(periodIndex, parameters); addTrackSelectionInternal(periodIndex, parameters);
} }
} }
} catch (ExoPlaybackException e) {
throw new IllegalStateException(e);
}
} }
/** /**
...@@ -683,6 +695,7 @@ public final class DownloadHelper { ...@@ -683,6 +695,7 @@ public final class DownloadHelper {
*/ */
public void addTextLanguagesToSelection( public void addTextLanguagesToSelection(
boolean selectUndeterminedTextLanguage, String... languages) { boolean selectUndeterminedTextLanguage, String... languages) {
try {
assertPreparedWithMedia(); assertPreparedWithMedia();
TrackSelectionParameters.Builder parametersBuilder = TrackSelectionParameters.Builder parametersBuilder =
...@@ -706,6 +719,9 @@ public final class DownloadHelper { ...@@ -706,6 +719,9 @@ public final class DownloadHelper {
addTrackSelectionInternal(periodIndex, parameters); addTrackSelectionInternal(periodIndex, parameters);
} }
} }
} catch (ExoPlaybackException e) {
throw new IllegalStateException(e);
}
} }
/** /**
...@@ -724,6 +740,7 @@ public final class DownloadHelper { ...@@ -724,6 +740,7 @@ public final class DownloadHelper {
int rendererIndex, int rendererIndex,
DefaultTrackSelector.Parameters trackSelectorParameters, DefaultTrackSelector.Parameters trackSelectorParameters,
List<SelectionOverride> overrides) { List<SelectionOverride> overrides) {
try {
assertPreparedWithMedia(); assertPreparedWithMedia();
DefaultTrackSelector.ParametersBuilder builder = trackSelectorParameters.buildUpon(); DefaultTrackSelector.ParametersBuilder builder = trackSelectorParameters.buildUpon();
for (int i = 0; i < mappedTrackInfos[periodIndex].getRendererCount(); i++) { for (int i = 0; i < mappedTrackInfos[periodIndex].getRendererCount(); i++) {
...@@ -732,12 +749,16 @@ public final class DownloadHelper { ...@@ -732,12 +749,16 @@ public final class DownloadHelper {
if (overrides.isEmpty()) { if (overrides.isEmpty()) {
addTrackSelectionInternal(periodIndex, builder.build()); addTrackSelectionInternal(periodIndex, builder.build());
} else { } else {
TrackGroupArray trackGroupArray = mappedTrackInfos[periodIndex].getTrackGroups(rendererIndex); TrackGroupArray trackGroupArray =
mappedTrackInfos[periodIndex].getTrackGroups(rendererIndex);
for (int i = 0; i < overrides.size(); i++) { for (int i = 0; i < overrides.size(); i++) {
builder.setSelectionOverride(rendererIndex, trackGroupArray, overrides.get(i)); builder.setSelectionOverride(rendererIndex, trackGroupArray, overrides.get(i));
addTrackSelectionInternal(periodIndex, builder.build()); addTrackSelectionInternal(periodIndex, builder.build());
} }
} }
} catch (ExoPlaybackException e) {
throw new IllegalStateException(e);
}
} }
/** /**
...@@ -794,7 +815,8 @@ public final class DownloadHelper { ...@@ -794,7 +815,8 @@ public final class DownloadHelper {
"mediaPreparer.timeline" "mediaPreparer.timeline"
}) })
private void addTrackSelectionInternal( private void addTrackSelectionInternal(
int periodIndex, TrackSelectionParameters trackSelectionParameters) { int periodIndex, TrackSelectionParameters trackSelectionParameters)
throws ExoPlaybackException {
trackSelector.setParameters(trackSelectionParameters); trackSelector.setParameters(trackSelectionParameters);
runTrackSelection(periodIndex); runTrackSelection(periodIndex);
// TrackSelectionParameters can contain multiple overrides for each track type. The track // TrackSelectionParameters can contain multiple overrides for each track type. The track
...@@ -809,7 +831,7 @@ public final class DownloadHelper { ...@@ -809,7 +831,7 @@ public final class DownloadHelper {
} }
@SuppressWarnings("unchecked") // Initialization of array of Lists. @SuppressWarnings("unchecked") // Initialization of array of Lists.
private void onMediaPrepared() { private void onMediaPrepared() throws ExoPlaybackException {
checkNotNull(mediaPreparer); checkNotNull(mediaPreparer);
checkNotNull(mediaPreparer.mediaPeriods); checkNotNull(mediaPreparer.mediaPeriods);
checkNotNull(mediaPreparer.timeline); checkNotNull(mediaPreparer.timeline);
...@@ -879,8 +901,7 @@ public final class DownloadHelper { ...@@ -879,8 +901,7 @@ public final class DownloadHelper {
"mediaPreparer", "mediaPreparer",
"mediaPreparer.timeline" "mediaPreparer.timeline"
}) })
private TrackSelectorResult runTrackSelection(int periodIndex) { private TrackSelectorResult runTrackSelection(int periodIndex) throws ExoPlaybackException {
try {
TrackSelectorResult trackSelectorResult = TrackSelectorResult trackSelectorResult =
trackSelector.selectTracks( trackSelector.selectTracks(
rendererCapabilities, rendererCapabilities,
...@@ -921,10 +942,6 @@ public final class DownloadHelper { ...@@ -921,10 +942,6 @@ public final class DownloadHelper {
} }
} }
return trackSelectorResult; return trackSelectorResult;
} catch (ExoPlaybackException e) {
// DefaultTrackSelector does not throw exceptions during track selection.
throw new UnsupportedOperationException(e);
}
} }
private static MediaSource createMediaSourceInternal( private static MediaSource createMediaSourceInternal(
...@@ -1095,7 +1112,14 @@ public final class DownloadHelper { ...@@ -1095,7 +1112,14 @@ public final class DownloadHelper {
} }
switch (msg.what) { switch (msg.what) {
case DOWNLOAD_HELPER_CALLBACK_MESSAGE_PREPARED: case DOWNLOAD_HELPER_CALLBACK_MESSAGE_PREPARED:
try {
downloadHelper.onMediaPrepared(); downloadHelper.onMediaPrepared();
} catch (ExoPlaybackException e) {
downloadHelperHandler
.obtainMessage(
DOWNLOAD_HELPER_CALLBACK_MESSAGE_FAILED, /* obj= */ new IOException(e))
.sendToTarget();
}
return true; return true;
case DOWNLOAD_HELPER_CALLBACK_MESSAGE_FAILED: case DOWNLOAD_HELPER_CALLBACK_MESSAGE_FAILED:
release(); release();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment