diff --git a/android/src/main/java/io/github/jofr/capacitor/mediasessionplugin/MediaSessionPlugin.java b/android/src/main/java/io/github/jofr/capacitor/mediasessionplugin/MediaSessionPlugin.java index 6f54b7f..a262897 100644 --- a/android/src/main/java/io/github/jofr/capacitor/mediasessionplugin/MediaSessionPlugin.java +++ b/android/src/main/java/io/github/jofr/capacitor/mediasessionplugin/MediaSessionPlugin.java @@ -88,6 +88,10 @@ public void startMediaService() { } private void updateServiceMetadata() { + if(service == null) { + return; + } + service.setTitle(title); service.setArtist(artist); service.setAlbum(album); @@ -141,6 +145,10 @@ public void setMetadata(PluginCall call) throws JSONException, IOException { } private void updateServicePlaybackState() { + if(service == null) { + return; + } + if (playbackState.equals("playing")) { service.setPlaybackState(PlaybackStateCompat.STATE_PLAYING); service.update(); @@ -170,6 +178,10 @@ public void setPlaybackState(PluginCall call) { } private void updateServicePositionState() { + if(service == null) { + return; + } + service.setDuration(Math.round(duration * 1000)); service.setPosition(Math.round(position * 1000)); float playbackSpeed = playbackRate == 0.0 ? (float) 1.0 : (float) playbackRate;