From b7e728dc0788a23af2eecb9f5870c3c612aa50a7 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 21 Oct 2016 18:13:59 -0700 Subject: Fix for Chromecast issues. Cast API appears to have changed so starting a new song triggers an additional COMPLETED broadcast while it is getting the new song ready --- .../java/github/daneren2005/dsub/service/ChromeCastController.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'app') 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 566ed773..f9e2bfb1 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/ChromeCastController.java +++ b/app/src/main/java/github/daneren2005/dsub/service/ChromeCastController.java @@ -23,6 +23,7 @@ import android.util.Log; import com.google.android.gms.cast.ApplicationMetadata; import com.google.android.gms.cast.Cast; import com.google.android.gms.cast.CastDevice; +import com.google.android.gms.cast.CastStatusCodes; import com.google.android.gms.cast.MediaInfo; import com.google.android.gms.cast.MediaMetadata; import com.google.android.gms.cast.MediaStatus; @@ -343,6 +344,8 @@ public class ChromeCastController extends RemoteController { public void onResult(RemoteMediaPlayer.MediaChannelResult result) { if (result.getStatus().isSuccess()) { // Handled in other handler + } else if(result.getStatus().getStatusCode() == CastStatusCodes.REPLACED) { + Log.w(TAG, "Request was replaced: " + currentPlaying.toString()); } else { Log.e(TAG, "Failed to load: " + result.getStatus().toString()); failedLoad(); @@ -459,7 +462,9 @@ public class ChromeCastController extends RemoteController { break; case MediaStatus.PLAYER_STATE_IDLE: if (mediaStatus.getIdleReason() == MediaStatus.IDLE_REASON_FINISHED) { - downloadService.onSongCompleted(); + if(downloadService.getPlayerState() != PlayerState.PREPARING) { + downloadService.onSongCompleted(); + } } else if (mediaStatus.getIdleReason() == MediaStatus.IDLE_REASON_INTERRUPTED) { if (downloadService.getPlayerState() != PlayerState.PREPARING) { downloadService.setPlayerState(PlayerState.PREPARING); -- cgit v1.2.3