aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/github
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2015-09-30 16:47:25 -0700
committerScott Jackson <daneren2005@gmail.com>2015-09-30 16:47:25 -0700
commit36405d93572ed5d005462f7fe2af5290e6ed1790 (patch)
treeafbae6c7d6ccdb4f576491d7f1b9bd6036f0b303 /app/src/main/java/github
parentf94c691751e065229959da1ff761fa0443ce9534 (diff)
downloaddsub-36405d93572ed5d005462f7fe2af5290e6ed1790.tar.gz
dsub-36405d93572ed5d005462f7fe2af5290e6ed1790.tar.bz2
dsub-36405d93572ed5d005462f7fe2af5290e6ed1790.zip
Fix NPE if trying to use handler before started
Diffstat (limited to 'app/src/main/java/github')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadService.java33
1 files changed, 23 insertions, 10 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 f0e119bb..7c0c9ba1 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
@@ -158,6 +158,7 @@ public class DownloadService extends Service {
private int timerDuration;
private long timerStart;
private boolean autoPlayStart = false;
+ private boolean runListenersOnInit = false;
private MediaRouteManager mediaRouter;
@@ -222,6 +223,13 @@ public class DownloadService extends Service {
mediaPlayerLooper = Looper.myLooper();
mediaPlayerHandler = new Handler(mediaPlayerLooper);
+
+ if(runListenersOnInit) {
+ onSongsChanged();
+ onSongProgress();
+ onStateUpdate();
+ }
+
Looper.loop();
}
}, "DownloadService").start();
@@ -1634,7 +1642,7 @@ public class DownloadService extends Service {
}
public void registerRoute(MediaRouter router) {
- if(mRemoteControl != null) {
+ if (mRemoteControl != null) {
mRemoteControl.registerRoute(router);
}
}
@@ -1922,6 +1930,7 @@ public class DownloadService extends Service {
}
}
}
+
public void reapplyVolume() {
applyReplayGain(mediaPlayer, currentPlaying);
}
@@ -2291,7 +2300,7 @@ public class DownloadService extends Service {
}
return null;
}
-
+
@Override
public void error(Throwable error) {
Log.e(TAG, "Failed to delete bookmark", error);
@@ -2453,14 +2462,18 @@ public class DownloadService extends Service {
}
if(run) {
- mediaPlayerHandler.post(new Runnable() {
- @Override
- public void run() {
- onSongsChanged();
- onSongProgress();
- onStateUpdate();
- }
- });
+ if(mediaPlayerHandler != null) {
+ mediaPlayerHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ onSongsChanged();
+ onSongProgress();
+ onStateUpdate();
+ }
+ });
+ } else {
+ runListenersOnInit = true;
+ }
}
}
public void removeOnSongChangeListener(OnSongChangedListener listener) {