aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Guy <glennguy83@gmail.com>2018-10-13 22:41:47 +1100
committerGlenn Guy <glennguy83@gmail.com>2018-10-13 22:41:47 +1100
commit9109204bbc34a42dd1a720cd341eb7a2a775d7cf (patch)
treea4a1699c6863d5136284e3e4c3a763528ef1ecb8
parent5f04bd8dfea5231fc248855c20edf4baec22f66b (diff)
downloaddsub-9109204bbc34a42dd1a720cd341eb7a2a775d7cf.tar.gz
dsub-9109204bbc34a42dd1a720cd341eb7a2a775d7cf.tar.bz2
dsub-9109204bbc34a42dd1a720cd341eb7a2a775d7cf.zip
Fix again registering/unregistering AudioNoisyReceiver
Moved to onCreate()/onDestroy() rather than start() stop() and pause() - receiver would not be registered in some cases causing and exception to occur and audio playback to continue when bluetooth is disconnected.
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadService.java10
1 files changed, 6 insertions, 4 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
index f4bc2343..9a0f606e 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
@@ -183,7 +183,7 @@ public class DownloadService extends Service {
private boolean runListenersOnInit = false;
private IntentFilter audioNoisyIntent = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
- private AudioNoisyReceiver audioNoisyReceiver = new AudioNoisyReceiver();
+ private AudioNoisyReceiver audioNoisyReceiver = null;
private MediaRouteManager mediaRouter;
@@ -267,6 +267,8 @@ public class DownloadService extends Service {
}, "DownloadService").start();
Util.registerMediaButtonEventReceiver(this);
+ audioNoisyReceiver = new AudioNoisyReceiver();
+ registerReceiver(audioNoisyReceiver, audioNoisyIntent);
if (mRemoteControl == null) {
// Use the remote control APIs (if available) to set the playback state
@@ -380,6 +382,9 @@ public class DownloadService extends Service {
proxy.stop();
proxy = null;
}
+ if (audioNoisyReceiver != null) {
+ unregisterReceiver(audioNoisyReceiver);
+ }
mediaRouter.destroy();
Notifications.hidePlayingNotification(this, this, handler);
Notifications.hideDownloadingNotification(this, this, handler);
@@ -1333,7 +1338,6 @@ public class DownloadService extends Service {
} else if(playerState == PAUSED_TEMP) {
setPlayerState(temp ? PAUSED_TEMP : PAUSED);
}
- unregisterReceiver(audioNoisyReceiver);
} catch (Exception x) {
handleError(x);
}
@@ -1358,7 +1362,6 @@ public class DownloadService extends Service {
} else if(playerState == PAUSED) {
setPlayerState(STOPPED);
}
- unregisterReceiver(audioNoisyReceiver);
} catch(Exception x) {
handleError(x);
}
@@ -1378,7 +1381,6 @@ public class DownloadService extends Service {
autoPlayStart = true;
}
}
- registerReceiver(audioNoisyReceiver, audioNoisyIntent);
setPlayerState(STARTED);
} catch (Exception x) {
handleError(x);