1

I recently switched my Chromecast app to a custom receiver. I'm still using the Cast Companion Library. The custom receiver is basically based on this https://github.com/googlecast/cast-custom-receiver/blob/master/sample_media_receiver.html the only changes are the adding of a logo and loading screen and commenting out this line appConfig.maxInactivity = 6000; although at first I didn't have it commented out and still had the same issue.

Anyways the issue is pretty simple and only happens to a few people. It happens to me with one of my test devices, not all and not always. Basically I start streaming a video and it is all fine, then the device screen goes off, when I turn it off again the app has disconnected from the Chromecast. I do not have wifi set to turn off when sleeping, and all of the users who have complained about this claim their devices also don't have that setting turned on.

It could be a coincidence that this happened when I switched to the custom receiver but I just wanted to make sure there wasn't something I needed to add to my custom receiver to tell the CCL code to stay connected?

Thanks.

2 Answers 2

5

I faced similar issue today. Main cause for this behaviour is that as soon as the sender (in your case phone) is locked (sleep mode) then senderDisconnected event is fired on the receiver side. And if you check the event.reason, it will be unknow, so you could probably check for the reason, if it unknown then dont stop the playback on receiver (window.close).

When the sender itself disconnects, event.reason is "disconnected_from_sender".

I hope this helps.

It has nothing to do with maxInactivity.

1
  • Thanks. This is exactly the problem with my device going to sleep mode and thus stopping the receiver app. Checking for event.reason along with keeping sending requests when going to sleep (task scheduler) allowed my app to continue running even in locked state. Commented Oct 9, 2015 at 7:26
1

The policy for disconnecting wifi when your phone goes to sleep does depend on the brand and vendor . Currently, the Cast SDK holds a lock to keep the wifi connected as long as there is a cast connection but even that is not a 100% guarantee to work for all phones/models/vendors/.... This has nothing to do with your receiver. The proper solution is not to try to fight against the wifi disconnect when phone goes to sleep, instead you have to consider adding some logic to recover the cast connectivity when phone wakes up and wifi connectivity is re-established (register a broadcast receiver to listen for wifi connectivity changes).

2
  • How can you "recover the cast connectivity" when receiver app has already closed? The only thing to prevent it from closing is to somehow keep sending requests even when in sleep mode (background service?). Commented Oct 9, 2015 at 7:24
  • The original post is not about receiver tearing down but rather the sender app getting disconnected. If you have a different question/situation, I suggest you post a new question.
    – Ali Naddaf
    Commented Oct 9, 2015 at 13:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.