mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Clarify threading requirement for MediaController.releaseFuture
And remove unnecessary check for isDone. Issue: androidx/media#345 PiperOrigin-RevId: 525999615
This commit is contained in:
parent
79fab6783e
commit
186f3d5c77
1 changed files with 7 additions and 4 deletions
|
|
@ -505,16 +505,19 @@ public class MediaController implements Player {
|
||||||
/**
|
/**
|
||||||
* Releases the future controller returned by {@link Builder#buildAsync()}. It makes sure that the
|
* Releases the future controller returned by {@link Builder#buildAsync()}. It makes sure that the
|
||||||
* controller is released by canceling the future if the future is not yet done.
|
* controller is released by canceling the future if the future is not yet done.
|
||||||
|
*
|
||||||
|
* <p>Must be called on the {@linkplain #getApplicationLooper() application thread} of the media
|
||||||
|
* controller.
|
||||||
*/
|
*/
|
||||||
public static void releaseFuture(Future<? extends MediaController> controllerFuture) {
|
public static void releaseFuture(Future<? extends MediaController> controllerFuture) {
|
||||||
if (!controllerFuture.isDone()) {
|
if (controllerFuture.cancel(/* mayInterruptIfRunning= */ true)) {
|
||||||
controllerFuture.cancel(/* mayInterruptIfRunning= */ true);
|
// Successfully canceled the Future. The controller will be released by MediaControllerHolder.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MediaController controller;
|
MediaController controller;
|
||||||
try {
|
try {
|
||||||
controller = controllerFuture.get();
|
controller = Futures.getDone(controllerFuture);
|
||||||
} catch (CancellationException | ExecutionException | InterruptedException e) {
|
} catch (CancellationException | ExecutionException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
controller.release();
|
controller.release();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue