Fix image not ignored for non-images in setImageDurationMs
PiperOrigin-RevId: 634345071
This commit is contained in:
parent
e23cc756e2
commit
7b2a1b4443
@ -9,6 +9,8 @@
|
|||||||
handle these additional calls with `mediaItemIndex == C.INDEX_UNSET`.
|
handle these additional calls with `mediaItemIndex == C.INDEX_UNSET`.
|
||||||
* Remove compile dependency on enhanced Java 8 desugaring
|
* Remove compile dependency on enhanced Java 8 desugaring
|
||||||
([#1312](https://github.com/androidx/media/issues/1312)).
|
([#1312](https://github.com/androidx/media/issues/1312)).
|
||||||
|
* Ensure the duration passed to `MediaItem.Builder.setImageDurationMs` is
|
||||||
|
ignored for a non-image `MediaItem` (as documented).
|
||||||
* ExoPlayer:
|
* ExoPlayer:
|
||||||
* Add `reset` to `BasePreloadManager` to release all the holding sources
|
* Add `reset` to `BasePreloadManager` to release all the holding sources
|
||||||
while keep the preload manager instance.
|
while keep the preload manager instance.
|
||||||
|
@ -573,7 +573,10 @@ public final class MediaItem implements Bundleable {
|
|||||||
/**
|
/**
|
||||||
* Sets the image duration in video output, in milliseconds.
|
* Sets the image duration in video output, in milliseconds.
|
||||||
*
|
*
|
||||||
* <p>Must be set if {@linkplain #setUri the uri} is set and resolves to an image. Ignored
|
* <p>Must be set if {@linkplain #setUri the URI} is set and resolves to an image. Ignored
|
||||||
|
* otherwise.
|
||||||
|
*
|
||||||
|
* <p>Motion photos will be rendered as images if this parameter is set, and as videos
|
||||||
* otherwise.
|
* otherwise.
|
||||||
*
|
*
|
||||||
* <p>Default value is {@link C#TIME_UNSET}.
|
* <p>Default value is {@link C#TIME_UNSET}.
|
||||||
|
@ -114,13 +114,13 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
private final Allocator allocator;
|
private final Allocator allocator;
|
||||||
@Nullable private final String customCacheKey;
|
@Nullable private final String customCacheKey;
|
||||||
private final long continueLoadingCheckIntervalBytes;
|
private final long continueLoadingCheckIntervalBytes;
|
||||||
|
private final long singleSampleDurationUs;
|
||||||
private final Loader loader;
|
private final Loader loader;
|
||||||
private final ProgressiveMediaExtractor progressiveMediaExtractor;
|
private final ProgressiveMediaExtractor progressiveMediaExtractor;
|
||||||
private final ConditionVariable loadCondition;
|
private final ConditionVariable loadCondition;
|
||||||
private final Runnable maybeFinishPrepareRunnable;
|
private final Runnable maybeFinishPrepareRunnable;
|
||||||
private final Runnable onContinueLoadingRequestedRunnable;
|
private final Runnable onContinueLoadingRequestedRunnable;
|
||||||
private final Handler handler;
|
private final Handler handler;
|
||||||
private final boolean isSingleSample;
|
|
||||||
|
|
||||||
@Nullable private Callback callback;
|
@Nullable private Callback callback;
|
||||||
@Nullable private IcyHeaders icyHeaders;
|
@Nullable private IcyHeaders icyHeaders;
|
||||||
@ -130,6 +130,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
|
|
||||||
private boolean prepared;
|
private boolean prepared;
|
||||||
private boolean haveAudioVideoTracks;
|
private boolean haveAudioVideoTracks;
|
||||||
|
private boolean isSingleSample;
|
||||||
private @MonotonicNonNull TrackState trackState;
|
private @MonotonicNonNull TrackState trackState;
|
||||||
private @MonotonicNonNull SeekMap seekMap;
|
private @MonotonicNonNull SeekMap seekMap;
|
||||||
private long durationUs;
|
private long durationUs;
|
||||||
@ -194,8 +195,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
this.continueLoadingCheckIntervalBytes = continueLoadingCheckIntervalBytes;
|
this.continueLoadingCheckIntervalBytes = continueLoadingCheckIntervalBytes;
|
||||||
loader = new Loader("ProgressiveMediaPeriod");
|
loader = new Loader("ProgressiveMediaPeriod");
|
||||||
this.progressiveMediaExtractor = progressiveMediaExtractor;
|
this.progressiveMediaExtractor = progressiveMediaExtractor;
|
||||||
this.durationUs = singleSampleDurationUs;
|
this.singleSampleDurationUs = singleSampleDurationUs;
|
||||||
isSingleSample = singleSampleDurationUs != C.TIME_UNSET;
|
|
||||||
loadCondition = new ConditionVariable();
|
loadCondition = new ConditionVariable();
|
||||||
maybeFinishPrepareRunnable = this::maybeFinishPrepare;
|
maybeFinishPrepareRunnable = this::maybeFinishPrepare;
|
||||||
onContinueLoadingRequestedRunnable =
|
onContinueLoadingRequestedRunnable =
|
||||||
@ -745,20 +745,12 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
|
|
||||||
private void setSeekMap(SeekMap seekMap) {
|
private void setSeekMap(SeekMap seekMap) {
|
||||||
this.seekMap = icyHeaders == null ? seekMap : new Unseekable(/* durationUs= */ C.TIME_UNSET);
|
this.seekMap = icyHeaders == null ? seekMap : new Unseekable(/* durationUs= */ C.TIME_UNSET);
|
||||||
if (seekMap.getDurationUs() == C.TIME_UNSET && durationUs != C.TIME_UNSET) {
|
durationUs = seekMap.getDurationUs();
|
||||||
this.seekMap =
|
|
||||||
new ForwardingSeekMap(this.seekMap) {
|
|
||||||
@Override
|
|
||||||
public long getDurationUs() {
|
|
||||||
return durationUs;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
durationUs = this.seekMap.getDurationUs();
|
|
||||||
isLive = !isLengthKnown && seekMap.getDurationUs() == C.TIME_UNSET;
|
isLive = !isLengthKnown && seekMap.getDurationUs() == C.TIME_UNSET;
|
||||||
dataType = isLive ? C.DATA_TYPE_MEDIA_PROGRESSIVE_LIVE : C.DATA_TYPE_MEDIA;
|
dataType = isLive ? C.DATA_TYPE_MEDIA_PROGRESSIVE_LIVE : C.DATA_TYPE_MEDIA;
|
||||||
listener.onSourceInfoRefreshed(durationUs, seekMap.isSeekable(), isLive);
|
if (prepared) {
|
||||||
if (!prepared) {
|
listener.onSourceInfoRefreshed(durationUs, seekMap.isSeekable(), isLive);
|
||||||
|
} else {
|
||||||
maybeFinishPrepare();
|
maybeFinishPrepare();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -783,6 +775,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
boolean isAudioVideo = isAudio || MimeTypes.isVideo(mimeType);
|
boolean isAudioVideo = isAudio || MimeTypes.isVideo(mimeType);
|
||||||
trackIsAudioVideoFlags[i] = isAudioVideo;
|
trackIsAudioVideoFlags[i] = isAudioVideo;
|
||||||
haveAudioVideoTracks |= isAudioVideo;
|
haveAudioVideoTracks |= isAudioVideo;
|
||||||
|
boolean isImage = MimeTypes.isImage(mimeType);
|
||||||
|
isSingleSample = singleSampleDurationUs != C.TIME_UNSET && trackCount == 1 && isImage;
|
||||||
@Nullable IcyHeaders icyHeaders = this.icyHeaders;
|
@Nullable IcyHeaders icyHeaders = this.icyHeaders;
|
||||||
if (icyHeaders != null) {
|
if (icyHeaders != null) {
|
||||||
if (isAudio || sampleQueueTrackIds[i].isIcyTrack) {
|
if (isAudio || sampleQueueTrackIds[i].isIcyTrack) {
|
||||||
@ -807,6 +801,17 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
trackArray[i] = new TrackGroup(/* id= */ Integer.toString(i), trackFormat);
|
trackArray[i] = new TrackGroup(/* id= */ Integer.toString(i), trackFormat);
|
||||||
}
|
}
|
||||||
trackState = new TrackState(new TrackGroupArray(trackArray), trackIsAudioVideoFlags);
|
trackState = new TrackState(new TrackGroupArray(trackArray), trackIsAudioVideoFlags);
|
||||||
|
if (isSingleSample && durationUs == C.TIME_UNSET) {
|
||||||
|
durationUs = singleSampleDurationUs;
|
||||||
|
seekMap =
|
||||||
|
new ForwardingSeekMap(seekMap) {
|
||||||
|
@Override
|
||||||
|
public long getDurationUs() {
|
||||||
|
return durationUs;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
listener.onSourceInfoRefreshed(durationUs, seekMap.isSeekable(), isLive);
|
||||||
prepared = true;
|
prepared = true;
|
||||||
checkNotNull(callback).onPrepared(this);
|
checkNotNull(callback).onPrepared(this);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user