From 3f97c4c2be24ceeea1d9ca067950820f1d2896d8 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 18 Sep 2015 09:04:15 -0700 Subject: Pull duration from media player first, fix position/duration not updating during buffering --- .../daneren2005/dsub/service/DownloadService.java | 34 ++++++++++++++-------- 1 file changed, 22 insertions(+), 12 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 a828ae4a..d69bf431 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java @@ -1249,23 +1249,30 @@ public class DownloadService extends Service { } public synchronized int getPlayerDuration() { - if (currentPlaying != null) { - Integer duration = currentPlaying.getSong().getDuration(); - if (duration != null) { - return duration * 1000; - } - } if (playerState != IDLE && playerState != DOWNLOADING && playerState != PlayerState.PREPARING) { + int duration = 0; if(remoteState == LOCAL) { try { - return mediaPlayer.getDuration(); + duration = mediaPlayer.getDuration(); } catch (Exception x) { - handleError(x); + duration = 0; } } else { - return remoteController.getRemoteDuration() * 1000; + duration = remoteController.getRemoteDuration() * 1000; + } + + if(duration != 0) { + return duration; + } + } + + if (currentPlaying != null) { + Integer duration = currentPlaying.getSong().getDuration(); + if (duration != null) { + return duration * 1000; } } + return 0; } @@ -2475,9 +2482,12 @@ public class DownloadService extends Service { }); } - if(playerState != STARTED) { - onSongProgress(); - } + mediaPlayerHandler.post(new Runnable() { + @Override + public void run() { + onSongProgress(); + } + }); } private void onSongsChanged() { final long atRevision = revision; -- cgit v1.2.3