diff --git a/RELEASENOTES.md b/RELEASENOTES.md index a9ead31b88..9f3a980d7c 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -89,6 +89,8 @@ ([#59](https://github.com/androidx/media/pull/59)) * Update session position info on timeline change([#51](https://github.com/androidx/media/issues/51)) + * Fix NPE in MediaControllerImplBase after releasing controller + ([#74](https://github.com/androidx/media/issues/74)) * Data sources: diff --git a/libraries/session/src/main/java/androidx/media3/session/MediaControllerImplBase.java b/libraries/session/src/main/java/androidx/media3/session/MediaControllerImplBase.java index 9c5efc8be6..b2420b835a 100644 --- a/libraries/session/src/main/java/androidx/media3/session/MediaControllerImplBase.java +++ b/libraries/session/src/main/java/androidx/media3/session/MediaControllerImplBase.java @@ -309,6 +309,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; serviceConnection = null; } connectedToken = null; + flushCommandQueueHandler.removeCallbacksAndMessages(/* token= */ null); this.iSession = null; controllerStub.destroy(); if (iSession != null) { @@ -3046,9 +3047,9 @@ import org.checkerframework.checker.nullness.qual.NonNull; } public void sendFlushCommandQueueMessage() { - // Send message to notify the end of the transaction. It will be handled when the current - // looper iteration is over. - if (!hasMessages(MSG_FLUSH_COMMAND_QUEUE)) { + if (iSession != null && !hasMessages(MSG_FLUSH_COMMAND_QUEUE)) { + // Send message to notify the end of the transaction. It will be handled when the current + // looper iteration is over. sendEmptyMessage(MSG_FLUSH_COMMAND_QUEUE); } }