From 678949d6724efe3cafb70008e9d91e28a18bdf46 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 22 Mar 2014 00:47:38 -0700 Subject: Try reconnecting on app startup --- .../daneren2005/dsub/service/DownloadService.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index 9c7cb459..7cf76e4f 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -1186,7 +1186,7 @@ public class DownloadService extends Service { } if(routeId != null) { - handler.post(new Runnable() { + final Runnable delayedReconnect = new Runnable() { @Override public void run() { RouteInfo info = mediaRouter.getRouteForId(routeId); @@ -1198,6 +1198,23 @@ public class DownloadService extends Service { setRemoteState(RemoteControlState.CHROMECAST, controller); } } + mediaRouter.stopScan(); + } + }; + + handler.post(new Runnable() { + @Override + public void run() { + mediaRouter.startScan(); + RouteInfo info = mediaRouter.getRouteForId(routeId); + if(info == null) { + handler.postDelayed(delayedReconnect, 2000L); + } else if(newState == RemoteControlState.CHROMECAST) { + RemoteController controller = mediaRouter.getRemoteController(info); + if(controller != null) { + setRemoteState(RemoteControlState.CHROMECAST, controller); + } + } } }); } -- cgit v1.2.3