From 1bab06f14458468b3d0e7e12ec87c0af7bcea678 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 12 May 2015 08:34:49 -0700 Subject: Fix crashes if trying to use before properly initialized --- .../dsub/util/compat/RemoteControlClientICS.java | 24 +++++++++++++++++++--- .../dsub/util/compat/RemoteControlClientJB.java | 4 ++++ 2 files changed, 25 insertions(+), 3 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java b/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java index 50283da6..46b6b47d 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java +++ b/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java @@ -42,17 +42,27 @@ public class RemoteControlClientICS extends RemoteControlClientHelper { } public void unregister(final Context context) { - if (mRemoteControl != null) { - AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); - audioManager.unregisterRemoteControlClient(mRemoteControl); + if(mRemoteControl == null) { + return; } + + AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); + audioManager.unregisterRemoteControlClient(mRemoteControl); } public void setPlaybackState(final int state) { + if(mRemoteControl == null) { + return; + } + mRemoteControl.setPlaybackState(state); } public void updateMetadata(final Context context, final MusicDirectory.Entry currentSong) { + if(mRemoteControl == null) { + return; + } + if(imageLoader == null) { imageLoader = SubsonicActivity.getStaticImageLoader(context); } @@ -72,11 +82,19 @@ public class RemoteControlClientICS extends RemoteControlClientHelper { @Override public void registerRoute(MediaRouter router) { + if(mRemoteControl == null) { + return; + } + router.addRemoteControlClient(mRemoteControl); } @Override public void unregisterRoute(MediaRouter router) { + if(mRemoteControl == null) { + return; + } + router.removeRemoteControlClient(mRemoteControl); } diff --git a/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientJB.java b/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientJB.java index c27df2ba..e61e9a47 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientJB.java +++ b/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientJB.java @@ -43,6 +43,10 @@ public class RemoteControlClientJB extends RemoteControlClientICS { @Override public void setPlaybackState(final int state) { + if(mRemoteControl == null) { + return; + } + long position = -1; if(state == RemoteControlClient.PLAYSTATE_PLAYING || state == RemoteControlClient.PLAYSTATE_PAUSED) { position = downloadService.getPlayerPosition(); -- cgit v1.2.3