androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.68k stars 399 forks source link

Image is skipped when mixing image and video media items in a exoplayer playlist #1017

Open kleiren opened 9 months ago

kleiren commented 9 months ago

Version

Media3 pre-release (alpha, beta or RC not in this list)

More version details

1.3.0-alpha01

Devices that reproduce the issue

OnePlus Nord running Android 11 Emulator running Android 14 Emulator running Android 10

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

In a default exoplayer with a simple ImageOutput set, setting a playlist with multiple media items: e.g.: mediaItems.add(imageMediaItemBuilder1.setImageDurationMs(3000).build()) //[Image1] mediaItems.add(imageMediaItemBuilder2.setImageDurationMs(3000).build()) //[Image2] mediaItems.add(videoMediaItem) //[Video] videoPlayer.setMediaItems(mediaItems) videoPlayer.playWhenReady = true videoPlayer.prepare()

Expected result

Image 1 is shown 3000 ms, Image 2 is shown 3000 ms, Video is played in its entirety.

Actual result

The image right before the video is shown just a few milliseconds, transitioning directly to the video. That is, Image1 is shown 3000 ms, Image2 is shown a few ms, Video is played in its entirety.

For some reason, it seems having a video next in the playlist "overrides" the current image.

When the media items are only images it works as expected (all images are shown the set ms) and with only video it works as expected

Media

Not applicable

Bug Report

pawaom commented 8 months ago

How are you displaying image and video in playlist can you share some sample code

microkatz commented 7 months ago

Hello @kleiren,

Thank you for reporting your issue! We submitted some fixes that should address the problem. These commits, 8b219b0 and 638b2a3 were pushed into the androidx/media main branch. With the fixes, Images with set duration should not be skipped in the mixed video, image playlist.

Hopefully that helps!

kleiren commented 6 months ago

Hi @microkatz Just tried version 1.3.1. It seems all images are being sent through the ImageOutput (inside onImageAvailable()).

However, ImageOutput.onDisabled() seems to be being called immediately after the last onImageAvailable(). In my case, I am using ImageOutput.onDisabled() to hide the view where the images are being shown, with the exoplayer view below showing the videos from the media sequence.

For example, for 2 images and a video in sequence. Image 1 is shown correctly, the second image is shown for a few millis instead of its full presentation time (as on disabled is immediately called, hiding the view and showing what's below) and then the video is shown in the exoplayer view.

Should I use something different than onDisabled() to know when the current image has to stop being shown?

Thanks for the work!

microkatz commented 6 months ago

Hi @kleiren.

Glad that progress has been made. The original issue was addressed by the player not transitioning its clock to the subsequent media item until the item has started(aka the play time has reached the next start position). I see that there is still a prevailing issue of the ImageRenderer finishing its renderering duties as soon as it offers that last image.

Thank you for reporting this new issue. We will need a little time to figure out the best solution.

In the meantime, may I suggest using the onMediaItemTransition callback? Hopefully that will provide ample notification for when the playback transitions to an item that is video vs image for switching your UI views.