0

I'm trying to communicate with Chromecast using Http. I'm using this documentation about API methods and trying to execute an Youtube video on it. Following this answer to execute a post call, for now I have:

@Override
public void run() {
    try {

        String urlParameters = "v=oHg5SJYRHA0";
        byte[] postData = urlParameters.getBytes();
        int postLenght = postData.length;
        //url is: new URL("http://192.168.25.99:8008/apps/YouTube")
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setDoOutput(true);
        urlConnection.setInstanceFollowRedirects(true);
        urlConnection.setRequestMethod("POST");
        urlConnection.setRequestProperty("Content-Type", "application/json");
        urlConnection.setRequestProperty("Content-Length", Integer.toString(postLenght));
        urlConnection.setUseCaches(false);
        DataOutputStream wr = new DataOutputStream(urlConnection.getOutputStream());
        wr.write(postData);
        wr.flush();
        wr.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

This command execute properly but nothing happening in Chromecast.

What am I doing wrong?

Community
  • 1
  • 1
alexpfx
  • 6,412
  • 12
  • 52
  • 88

1 Answers1

0

It works, I just forgot to call the response:

String responseMessage = urlConnection.getResponseMessage();

When I call this method, the video executes.

alexpfx
  • 6,412
  • 12
  • 52
  • 88