6

The use case is that a user starts playback from their iPhone, lets say, and then picks up their iPad (both running my app) and wants to contect to and control the running video from this other iOS device.

On iOS, I do not see any way to determine if there is a instance of my receiver app already running on the Google ChromeCast device. Once I create my session it seems the only thing I can do is to attach a new protocol message stream, which interrupts whatever might be playing already.

It this suppose to be handled in the iOS client side Framework, perhaps there is some coding I need to do in the HTML receiver app?

Thanks.

greg
  • 61
  • 1
  • 3

2 Answers2

6

There is a way outside the API to determine if an app is running. Do a HTTP GET on the apps URL for the ChromeCast IP address: http://192.168.0.x:8008/apps/ If the HTTP response is 200, nothing is running. If the HTTP response is 204, then an app is running and the HTTP response would be redirected to a URL like: http://192.168.0.x:8008/apps/GoogleMusic

Which tells you which app is running.

Interestingly, Google Play Music cannot be controlled by 2 devices simultaneously, but YouTube can. I suspect Play Music is using RAMP which is what the Cast SDK does for media streams. YouTube could be using a proprietary message stream to control the media playback. So you might have to do the same if you want to have the an app on a device controlled by multiple sender apps.

Leon Nicholls
  • 4,623
  • 2
  • 16
  • 17
  • Thanks Leon, that is helpful information, I will end up using it. Turns out the answer I was after was to just not pass an application argument to startSessionWithApplication:, doing that will connect to the existing chromecast session gracefully. If you do pass an argument, it will tear down the existing session and build up a new one from your receiver app. This does assume that the same app is running on there of course (same appID). – greg Aug 30 '13 at 16:19
  • Leon, I have a similar use case: I am casting a youtube video, and in a separate script I want to get the current session. Basically what I want it to get the complete URL of the youtube video, which includes the video ID. The video ID is what I am after! Should I start a separate question and maybe you could reply to it there? – Ali Feb 25 '14 at 06:31
  • As of Aug '17, I get a `204 No content` response, regardless of device state – Dermot Aug 09 '17 at 09:56
2

One method is to check the playStatus after you start your session and before you initiate a loadMedia(). If your app is already running - it should return a non-nil (ie. IDLE, PLAYING, ...) result.

Paul Carff
  • 316
  • 2
  • 4
  • Thanks, I will try that now and report back. – greg Aug 15 '13 at 19:29
  • Well, that did not seem to work. I get a player state of -1 (Unknown) every time. I do get a little different behavior though depending on how I start the session. If I pass a applicationArgument then the current running receiver is killed before I ever get the call back. The other forms are startSession don't kill the running receiver, but they always return a player state of -1 (all other status info seems uninitialized as well). – greg Aug 15 '13 at 20:15
  • 1
    How do you request the player state? – osxdirk Nov 28 '16 at 19:37