From b0ff9eae88acccdbc332a8aa51aba019be616675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Sun, 28 Jan 2024 20:26:31 +0000 Subject: [PATCH] MusicManager: Fix NPE when music not playing --- .../gadgetbridge/util/MediaManager.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/MediaManager.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/MediaManager.java index 3527da011..af76060c9 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/MediaManager.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/MediaManager.java @@ -24,6 +24,8 @@ import android.media.session.MediaController; import android.media.session.MediaSessionManager; import android.media.session.PlaybackState; +import androidx.annotation.Nullable; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -105,7 +107,12 @@ public class MediaManager { } } + @Nullable public static MusicSpec extractMusicSpec(final MediaMetadata d) { + if (d == null) { + return null; + } + final MusicSpec musicSpec = new MusicSpec(); try { @@ -128,7 +135,12 @@ public class MediaManager { return musicSpec; } + @Nullable public static MusicStateSpec extractMusicStateSpec(final PlaybackState s) { + if (s == null) { + return null; + } + final MusicStateSpec stateSpec = new MusicStateSpec(); try {