aboutsummaryrefslogtreecommitdiff
path: root/src/github
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-03-19 22:31:37 -0700
committerScott Jackson <daneren2005@gmail.com>2014-03-19 22:31:37 -0700
commitb314a1844b41918df2e3fe443b19c5072ca14e99 (patch)
tree3d2fa16cf96e8a026e184a90d37663d46493d7b1 /src/github
parent855017392ae445b12026c1959fe57f24eef70ad5 (diff)
downloaddsub-b314a1844b41918df2e3fe443b19c5072ca14e99.tar.gz
dsub-b314a1844b41918df2e3fe443b19c5072ca14e99.tar.bz2
dsub-b314a1844b41918df2e3fe443b19c5072ca14e99.zip
Attempt to reconnect to ChromeCast to fix random stopping
Diffstat (limited to 'src/github')
-rw-r--r--src/github/daneren2005/dsub/service/ChromeCastController.java55
1 files changed, 35 insertions, 20 deletions
diff --git a/src/github/daneren2005/dsub/service/ChromeCastController.java b/src/github/daneren2005/dsub/service/ChromeCastController.java
index 5a989fca..8e228047 100644
--- a/src/github/daneren2005/dsub/service/ChromeCastController.java
+++ b/src/github/daneren2005/dsub/service/ChromeCastController.java
@@ -62,6 +62,7 @@ public class ChromeCastController extends RemoteController {
private boolean waitingForReconnect = false;
private boolean error = false;
private boolean ignoreNextPaused = false;
+ private String sessionId;
private FileProxy proxy;
private String rootLocation;
@@ -363,17 +364,35 @@ public class ChromeCastController extends RemoteController {
private class ConnectionCallbacks implements GoogleApiClient.ConnectionCallbacks {
private boolean isPlaying;
private int position;
+ private ResultCallback<Cast.ApplicationConnectionResult> resultCallback;
ConnectionCallbacks(boolean isPlaying, int position) {
this.isPlaying = isPlaying;
this.position = position;
+
+ resultCallback = new ResultCallback<Cast.ApplicationConnectionResult>() {
+ @Override
+ public void onResult(Cast.ApplicationConnectionResult result) {
+ Status status = result.getStatus();
+ if (status.isSuccess()) {
+ ApplicationMetadata applicationMetadata = result.getApplicationMetadata();
+ sessionId = result.getSessionId();
+ String applicationStatus = result.getApplicationStatus();
+ boolean wasLaunched = result.getWasLaunched();
+
+ applicationStarted = true;
+ setupChannel();
+ } else {
+ shutdownInternal();
+ }
+ }
+ };
}
@Override
public void onConnected(Bundle connectionHint) {
if (waitingForReconnect) {
- waitingForReconnect = false;
- // reconnectChannels();
+ reconnectApplication();
} else {
launchApplication();
}
@@ -381,32 +400,24 @@ public class ChromeCastController extends RemoteController {
@Override
public void onConnectionSuspended(int cause) {
+ Log.w(TAG, "Connection suspended");
waitingForReconnect = true;
}
void launchApplication() {
try {
- Cast.CastApi.launchApplication(apiClient, CastCompat.APPLICATION_ID, false).setResultCallback(new ResultCallback<Cast.ApplicationConnectionResult>() {
- @Override
- public void onResult(Cast.ApplicationConnectionResult result) {
- Status status = result.getStatus();
- if (status.isSuccess()) {
- ApplicationMetadata applicationMetadata = result.getApplicationMetadata();
- String sessionId = result.getSessionId();
- String applicationStatus = result.getApplicationStatus();
- boolean wasLaunched = result.getWasLaunched();
-
- applicationStarted = true;
- setupChannel();
- } else {
- shutdownInternal();
- }
- }
- });
+ Cast.CastApi.launchApplication(apiClient, CastCompat.APPLICATION_ID, false).setResultCallback(resultCallback);
} catch (Exception e) {
Log.e(TAG, "Failed to launch application", e);
}
}
+ void reconnectApplication() {
+ try {
+ Cast.CastApi.joinApplication(apiClient, CastCompat.APPLICATION_ID, sessionId).setResultCallback(resultCallback);
+ } catch (Exception e) {
+ Log.e(TAG, "Failed to reconnect application", e);
+ }
+ }
void setupChannel() {
mediaPlayer = new RemoteMediaPlayer();
mediaPlayer.setOnStatusUpdatedListener(new RemoteMediaPlayer.OnStatusUpdatedListener() {
@@ -465,7 +476,11 @@ public class ChromeCastController extends RemoteController {
}
DownloadFile currentPlaying = downloadService.getCurrentPlaying();
- startSong(currentPlaying, isPlaying, position);
+ if(!waitingForReconnect) {
+ startSong(currentPlaying, isPlaying, position);
+ } else {
+ waitingForReconnect = false;
+ }
}
}