0

I'm developing an Android application that needs to send local data to the Chromecast device. The Cast.CastApi.sendMessage() method works fine for small messages (up to about 100KB, it seems) but I need to pass images that may be several MB in size.

It seems that the best way is to bind to a local port on the Android device and listen for connections, pass a URL that points to the Android device in a message, and have the Chromecast fetch the images that way.

The problem is that I don't know what IP address to include in the URL. The Android device may have several IP addresses, not all of which are reachable from the Chromecast. There are two possible solutions I can think of but don't know how to implement either of them:

  1. Extract on the Android the local IP address from the socket that is currently connected to the Chromecast. Use that as the host field in the URL.
  2. Extract on the Chromecast the remote IP address from the socket that is currently connected to the Android. Send a dummy host from the Android and have the Chromecast substitute the correct address it has extracted.

Any suggestion on how to actually accomplish either of these? Or another option?

Brian White
  • 8,332
  • 2
  • 43
  • 67

1 Answers1

1

To make the media that is on your phone accessible to your receiver application running on chromecast, the easiest approach is to run a tiny web server in your app; you can use, for example, the NanoHttpd project. Note that Chromecast expects http(s) protocol for media transport unless it is included in the receiver itself. After adding that server, you can get the ip address of your Android device by accessing the WiFi network interface of your phone, see this post for example.

Community
  • 1
  • 1
Ali Naddaf
  • 16,951
  • 2
  • 21
  • 28
  • I'm not worried about the server. For my purposes, I can just dump a stock HTTP response plus the image; I don't even have to parse the HTTP request because there is only every one image to send. But with or without a full local HTTP server, I need to know the *address* to use in the URL passed to the Chromecast -- the contents of my question. – Brian White Jun 29 '14 at 01:35
  • If you are using a local web server, then the full url is determined by your web server and how you set it up, it would be something like http://:/***; the ipaddress part is what I pointed to in the referenced post, what more is there for the ip address that you are asking? – Ali Naddaf Jun 29 '14 at 01:49
  • Getting the IP address of the WiFi interface is a good start. **However**, that is making the assumption that the communication is occurring over WiFi. I believe that is currently the only way but who knows what the future might hold. – Brian White Jun 29 '14 at 23:38