media icon indicating copy to clipboard operation
media copied to clipboard

Asynchronous onAddMediaItems immediately get skipped when seeking to them

Open lukel97 opened this issue 3 years ago • 1 comments

Hi there, we’ve been trying out the main branch for the onAddMediaItems callback which is exactly what we require for our use case: Our app adds a media item to the playlist via the controller but it only knows the media id of the item, the session itself then resolves the URL and metadata by communicating to an external server.

It’s been working great so far but the one edge case we’ve found so far is that when seeking to a media item that was just added, but not yet resolved, the player seems to immediately skip over it.

For example, if your playlist looks like

A C
^

where A is the currently playing media item, and then you add an “unresolved" media item B so it then becomes

A B C
^

If you seek to the next media item via seekToNextMediaItem, it immediately skips past B to C:

A B C
    ^

I’ve tested that this doesn’t happen if onAddMediaItems resolves immediately with a URI (via Futures.immediateFuture).

Is this by design? Or are we maybe misusing onAddMediaItems here?

The revision this is happening on is a105d033a7d44b8c3afb0e8134ad65f624caf256. (We’ve built snapshot artifacts here if anyone else is interested in riding the bleeding edge)

lukel97 avatar Jun 12 '22 01:06 lukel97

Thanks for reporting! We are actually aware that this may an issue that needs to be fixed.

The reason this is happening is the asynchronous nature of the method call. After calling addMediaItem, the media controller pretends the playlist already looks like A B C. The session, however, is running the asynchonous media item resolution (triggered by onAddMediaItems) and its playlist still looks like A C. The seek command will be resolved immediately, so that the session seek to its next item (C) first and only once the new item is resolved it will insert it into the playlist.

The solution will be to better enforce the ordering of commands even if some of them need asynchronous resolution (this applies to other asynchronous commands as well, e.g. setRating and custom commands).

tonihei avatar Jun 15 '22 07:06 tonihei

@tonihei could you please confirm in which release version this issue was fixed?

luizgrp avatar Dec 07 '22 10:12 luizgrp

If you use the latest version that is 1.0.0-beta03 then this is included.

marcbaechinger avatar Dec 07 '22 10:12 marcbaechinger