From 133aa31b1d36b9d7a7885fede29f0d3501e2c9ab Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 23 Sep 2015 08:43:55 -0700 Subject: Fix some random crashes --- .../daneren2005/dsub/service/DownloadService.java | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'app/src/main/java/github/daneren2005') 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 f95a2785..6c73e8c1 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java @@ -2470,7 +2470,7 @@ public class DownloadService extends Service { } } - private void onSongChanged() { + private synchronized void onSongChanged() { final long atRevision = revision; for(final OnSongChangedListener listener: onSongChangedListeners) { handler.post(new Runnable() { @@ -2483,14 +2483,16 @@ public class DownloadService extends Service { }); } - mediaPlayerHandler.post(new Runnable() { - @Override - public void run() { - onSongProgress(); - } - }); + if(mediaPlayerHandler != null && !onSongChangedListeners.isEmpty()) { + mediaPlayerHandler.post(new Runnable() { + @Override + public void run() { + onSongProgress(); + } + }); + } } - private void onSongsChanged() { + private synchronized void onSongsChanged() { final long atRevision = revision; for(final OnSongChangedListener listener: onSongChangedListeners) { handler.post(new Runnable() { @@ -2503,7 +2505,7 @@ public class DownloadService extends Service { }); } } - private void onSongProgress() { + private synchronized void onSongProgress() { final long atRevision = revision; final Integer duration = getPlayerDuration(); final boolean isSeekable = isSeekable(); -- cgit v1.2.3