media icon indicating copy to clipboard operation
media copied to clipboard

Events not called completely if a MediaItem is twice in the playlist.

Open tzugen opened this issue 2 years ago • 1 comments

I am listening to onMediaItemTransition, onIsPlayingChanged and onPlaybackStateChanged to detect when the current track has changed, and update the UI accordingly.

It all works fine. But if the same MediaItem is added twice to the playlist, then none of these Events are called when it transitions from one instance to the next, the only Event that is generated is a onPositionDiscontinuity which is a bit weird.

tzugen avatar Apr 18 '22 09:04 tzugen

That's a know behaviour coming from ExoPlayerImpl not notifying onMediaItemTransition when it would call the method again with the same parameters as the last call. We should see whether we want to reconsider this behaviour in ExoPlayerImpl.

I think for now you can detect this change when you are using onPositionDiscontinuity. This should be reported because the params of this callback differ when the described case happens.

marcbaechinger avatar May 09 '22 13:05 marcbaechinger

@marcbaechinger About onMediaItemTransition, how can I get informed about it for all cases it changes, even for the first item? Should I reach player.currentMediaItem?.mediaId on the first time onRenderedFirstFrame is called? or something else such as onPlaybackStateChanged for when it becomes STATE_READY) ?

AndroidDeveloperLB avatar Jun 01 '23 12:06 AndroidDeveloperLB

When using the demo app and play the sample Playlists - Cats -> Dogs I get the following events from onMediaItemTransitioned:

12336-12336  D  mediaItem [eventTime=0.00, mediaPos=0.00, window=0, reason=PLAYLIST_CHANGED]period=1, pos=0]]
12336-12336  D  renderedFirstFrame [eventTime=0.69, mediaPos=0.00, window=0, period=0, Surface(name=null)/@0xe9e8ee9]
12336-12336  D  mediaItem [eventTime=25.85, mediaPos=0.02, window=1, period=1, reason=AUTO]

The first event is emitted when player.getCurrentMediaItem() changes from null to the item that has been inserted with player.setMediaItems(mediaItems). The reason is therefore PLAYLIST_CHANGED and this happens at mediaPos=0.0. This happens before onFirstFrameRendered() is called an should do what you are asking for as afar as I understand.

Then it plays the first item and when playback transitions automatically to the second item it reports the change in player.getCurrentMediaItem() with reason AUTO.

how can I get informed about it for all cases it changes, even for the first item?

Can you elaborate what you are expecting and why you think you can't see the changes in media item?

marcbaechinger avatar Jun 01 '23 14:06 marcbaechinger

@marcbaechinger The onMediaItemTransition is called only after playing the first item that was added to the playlist (meaning from the second one). I want to be informed about the first one too. The issue that was mentioned here is that it doesn't get called on some cases, and I've noticed it's not being called for the first item as well.

AndroidDeveloperLB avatar Jun 01 '23 15:06 AndroidDeveloperLB

Sorry, I can't repro that (see comment above). The callback is called as expected when the media items are set. The only thing that comes to mind is that at this time the listener is not yet added.

I have verified, that when the first item is set and null is replaced, this works with the current version.

Feel free to provide more information on what you do. With the current information available I can not help some further because I can't repro the problem.

marcbaechinger avatar Jun 01 '23 16:06 marcbaechinger

@marcbaechinger Check attached sample (exoplayer-codelab-00):

exoplayer-intro-main.zip

AndroidDeveloperLB avatar Jun 01 '23 16:06 AndroidDeveloperLB

@AndroidDeveloperLB I think we have a bit of a communication problem according to https://github.com/google/ExoPlayer/issues/10238

I apologize not to be clear enough and I try to improve my service. Still, the king's way for getting help is to describe your problem as short as possible or provide a way in the demo app to repro.

If you instead send me an Android Studio project that contains various app projects so that it isn't even clear where I should look to, then you start to diminish your chance to get help quickly and efficiently.

As I argued before, the easiest and quickest way to get help, is to play the media with the demo app and report the findings with a bugreport and a media URI. It's at least worth a try to follow that recommendation.

For your convenience, I looked up the line in the file of the demo app that you have to edit to add a playlist: https://github.com/androidx/media/blob/release/demos/main/src/main/assets/media.exolist.json#L486

For this specific case, I propose the following:

  1. Add your media to the media.exolist.json that I referenced above.
  2. Add a filter in the logcat view of Android Studio and filter package:mine EventLogger
  3. Start playback and play the playlist
  4. Capture the logs and post it here.

marcbaechinger avatar Jun 01 '23 17:06 marcbaechinger

@marcbaechinger First of all , it's not a URL so not sure how to add it there. Second, the file became 0-sized on the way for some reason, so even if I knew how to add to this very customized JSON file , it wouldn't help.

Anyway, the issue is not about the file here. it's about the callback not being called. And the demo is far from being minimalistic. As for the sample app, I've mentioned which to start, as this is a demo project too, used from the website of Exoplayer tutorial.

I've now tried the demo you've told me about. You say it's unclear what to run on what I gave (even though I've mentioned what), and here it is the same. So I assume you mean the one called "demo". I added a listener and logs for it.

Sadly the demo doesn't demonstrate anything till I actually choose something in the UI. Not the same as the tutorial so I don't understand what I can do to show you the issue.

So I tried a different demo there, called "demo-surface". First, I have to say it has a serious bug, that it continues playing when I press home key. That's before I changed anything.

Second, this is what I changed:

Uri uri = RawResourceDataSource.buildRawResourceUri(R.raw.test2);
...
    ExoPlayer player = new ExoPlayer.Builder(getApplicationContext()).build();
    player.addListener(new Player.Listener() {
      @Override
      public void onMediaItemTransition(@Nullable MediaItem mediaItem, int reason) {
        Player.Listener.super.onMediaItemTransition(mediaItem, reason);
        Log.d("AppLog", "onMediaItemTransition");
      }
    });

I also tried this instead, which used to work fine in the past:

Uri uri = Uri.parse( "android.resource://"+getPackageName()+"/"+R.raw.test2);

So, weird thing is that now onMediaItemTransition is called twice, yet the video doesn't play.

Sadly as this demo is huge, I can't attach it here as one file, so here it is , split. You need to rename each to remove the last ".zip" extension: media.zip.001.zip media.zip.002.zip media.zip.003.zip media.zip.004.zip

AndroidDeveloperLB avatar Jun 01 '23 19:06 AndroidDeveloperLB

Sorry, but every question you are asking is already answered in one of the comments I gave you. That's my last comment directed to your problem. You can keep posting of course. We leave your issue open in case another users has some inputs for you.


It's about the main demo app as explained and linked in the other comment: https://developer.android.com/guide/topics/media/exoplayer/demo-application

Look at this comment above and play the sample I told you which is a playlist: https://github.com/androidx/media/issues/68#issuecomment-1572140072

Then observe the logs and filter fro EventLogger. If it does not work with your samples you are doing yourself, then I'm afraid it is the problem of that app you are trying.

marcbaechinger avatar Jun 01 '23 19:06 marcbaechinger

@marcbaechinger But as I wrote, the demo doesn't demonstrate playing right away, like what I need to do. It's also very complex and what I demonstrate is simply playing from "raw" folder. The sample I've attached is from the demo project you've linked to. It's inside...

How can I show you an issue if you insist on using the wrong scenario...

AndroidDeveloperLB avatar Jun 01 '23 20:06 AndroidDeveloperLB