From 39c7f5b302d20c24e274850e5f9c63a5df714c07 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 11 Feb 2016 22:17:04 -0800 Subject: Fix clicking play while casting not starting automatically --- .../dsub/service/ChromeCastController.java | 28 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'app/src/main/java/github') diff --git a/app/src/main/java/github/daneren2005/dsub/service/ChromeCastController.java b/app/src/main/java/github/daneren2005/dsub/service/ChromeCastController.java index bc54f486..c2007139 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/ChromeCastController.java +++ b/app/src/main/java/github/daneren2005/dsub/service/ChromeCastController.java @@ -62,6 +62,8 @@ public class ChromeCastController extends RemoteController { private boolean error = false; private boolean ignoreNextPaused = false; private String sessionId; + private boolean isStopping = false; + private Runnable afterUpdateComplete = null; private ServerProxy proxy; private String rootLocation; @@ -247,18 +249,38 @@ public class ChromeCastController extends RemoteController { } } - void startSong(DownloadFile currentPlaying, boolean autoStart, int position) { + void startSong(final DownloadFile currentPlaying, final boolean autoStart, final int position) { if(currentPlaying == null) { try { - if (mediaPlayer != null && !error) { - mediaPlayer.stop(apiClient); + if (mediaPlayer != null && !error && !isStopping) { + isStopping = true; + mediaPlayer.stop(apiClient).setResultCallback(new ResultCallback() { + @Override + public void onResult(RemoteMediaPlayer.MediaChannelResult mediaChannelResult) { + isStopping = false; + + if(afterUpdateComplete != null) { + afterUpdateComplete.run(); + afterUpdateComplete = null; + } + } + }); } } catch(Exception e) { // Just means it didn't need to be stopped } downloadService.setPlayerState(PlayerState.IDLE); return; + } else if(isStopping) { + afterUpdateComplete = new Runnable() { + @Override + public void run() { + startSong(currentPlaying, autoStart, position); + } + }; + return; } + downloadService.setPlayerState(PlayerState.PREPARING); MusicDirectory.Entry song = currentPlaying.getSong(); -- cgit v1.2.3