Skip to content

Commit

Permalink
Run MediaSessionStub commands in order
Browse files Browse the repository at this point in the history
Some commands are run asynchronously and subsequent commands need
to wait until the previous one finished. This can be supported
by returning a Future for each command and using the existing
command execution logic to wait for each Future to complete.

As some MediaSessionStub code is now executed delayed to when it
was originally created, we also need to check if the session is
not released before triggering any actions or sending result codes.

Issue: #85
PiperOrigin-RevId: 462101136
  • Loading branch information
tonihei authored and rohitjoins committed Jul 21, 2022
1 parent 45f1f5b commit 7cb7636
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 108 deletions.
4 changes: 4 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
`MetadataRenderer(MetadataOutput, Looper, MetadataDecoderFactory,
boolean)` to specify whether the renderer will output metadata early or
in sync with the player position.
* Session:
* Ensure commands are always executed in the correct order even if some
require asynchronous resolution
([#85](https://github.com/androidx/media/issues/85)).

### 1.0.0-beta02 (2022-07-15)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import androidx.media3.common.Player;
import androidx.media3.session.MediaSession.ControllerInfo;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import java.util.ArrayDeque;
Expand Down Expand Up @@ -227,15 +226,11 @@ public ControllerInfo getController(T controllerKey) {
}
}

public void addToCommandQueue(ControllerInfo controllerInfo, Runnable commandRunnable) {
public void addToCommandQueue(ControllerInfo controllerInfo, AsyncCommand asyncCommand) {
synchronized (lock) {
@Nullable ConnectedControllerRecord<T> info = controllerRecords.get(controllerInfo);
if (info != null) {
info.commandQueue.add(
() -> {
commandRunnable.run();
return Futures.immediateVoidFuture();
});
info.commandQueue.add(asyncCommand);
}
}
}
Expand Down
Loading

0 comments on commit 7cb7636

Please sign in to comment.