Fix cleared metadata when repeating the same item

Issue: androidx/media#1007

#minor-release

PiperOrigin-RevId: 600477540
This commit is contained in:
tonihei 2024-01-22 09:17:51 -08:00 committed by Copybara-Service
parent 94bf9fa81d
commit c6bf380d50
3 changed files with 31 additions and 1 deletions

View File

@ -10,6 +10,8 @@
by wrapping an instance using the by wrapping an instance using the
[decorator pattern](https://en.wikipedia.org/wiki/Decorator_pattern) and [decorator pattern](https://en.wikipedia.org/wiki/Decorator_pattern) and
implementing a custom `CompositeSequenceableLoaderFactory`. implementing a custom `CompositeSequenceableLoaderFactory`.
* Fix issue where repeating the same time causes metadata from this item
to be cleared ([#1007](https://github.com/androidx/media/issues/1007)).
* Transformer: * Transformer:
* Track Selection: * Track Selection:
* Extractors: * Extractors:

View File

@ -2019,7 +2019,8 @@ import java.util.concurrent.TimeoutException;
} }
staticAndDynamicMediaMetadata = MediaMetadata.EMPTY; staticAndDynamicMediaMetadata = MediaMetadata.EMPTY;
} }
if (!previousPlaybackInfo.staticMetadata.equals(newPlaybackInfo.staticMetadata)) { if (mediaItemTransitioned
|| !previousPlaybackInfo.staticMetadata.equals(newPlaybackInfo.staticMetadata)) {
staticAndDynamicMediaMetadata = staticAndDynamicMediaMetadata =
staticAndDynamicMediaMetadata staticAndDynamicMediaMetadata
.buildUpon() .buildUpon()

View File

@ -14227,6 +14227,33 @@ public final class ExoPlayerTest {
assertThat(positionAfterSeek).isEqualTo(0); assertThat(positionAfterSeek).isEqualTo(0);
} }
@Test
public void repeatingItemWithSameStaticMetadata_keepsMetadata() throws Exception {
Format formatWithStaticMetadata =
new Format.Builder()
.setSampleMimeType(MimeTypes.VIDEO_H264)
.setMetadata(
new Metadata(
new BinaryFrame(/* id= */ "", /* data= */ new byte[0]),
new TextInformationFrame(
/* id= */ "TT2",
/* description= */ null,
/* values= */ ImmutableList.of("title"))))
.build();
ExoPlayer player = new TestExoPlayerBuilder(context).build();
player.setMediaSource(new FakeMediaSource(new FakeTimeline(), formatWithStaticMetadata));
player.prepare();
player.setRepeatMode(Player.REPEAT_MODE_ONE);
player.play();
// Wait until item repeats.
runUntilPositionDiscontinuity(player, Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
MediaMetadata metadataAfterTransition = player.getMediaMetadata();
player.release();
assertThat(metadataAfterTransition.title).isEqualTo("title");
}
// Internal methods. // Internal methods.
private void addWatchAsSystemFeature() { private void addWatchAsSystemFeature() {