title: Java API for ChromeCast
body: <p>Is there any way to connect to a ChromeCast using standard ( desktop ) Java. I am looking for a way to automate our testing and would like our CC:s to play a video automatically.</p>
  
  <p>So far I have found this project:</p>
  
  <p><a href="https://github.com/vitalidze/chromecast-java-api-v2" rel="nofollow">https://github.com/vitalidze/chromecast-java-api-v2</a></p>
  
  <p>But so far I have not been able to get it working.</p>
  
  <p>I can find the Chromecast just fine using mDNS, but when I try to connect to it I just get a close from the CC.</p>
  
  <p>My testcode:</p>
  
  <pre><code>public static void main(String[] args) {
      try {
  
          ChromeCasts.startDiscovery();
  
          // Wait for CC:s to apear
          Thread.sleep(5000);
  
          for (ChromeCast cc : ChromeCasts.get()) {
  
              if (cc.getName().equals("cc02")) {
                  cc.connect();
  
                  Status status = cc.getStatus();
  
                  cc.disconnect();
              }
          }
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>The result from the log:</p>
  
  <p>2015-12-15 19:14:37,727 DEBUG [main] su.litvak.chromecast.api.v2.Channel -   --> {"type":"StandardMessage$Ping"}
  2015-12-15 19:14:37,769 DEBUG [main] su.litvak.chromecast.api.v2.Channel -   --> {"type":"StandardMessage$Connect","origin":{}}
  2015-12-15 19:14:37,794 DEBUG [main] su.litvak.chromecast.api.v2.Channel -   --> {"type":"StandardRequest$Status","requestId":1}
  2015-12-15 19:14:37,802 DEBUG [Thread-4] su.litvak.chromecast.api.v2.Channel -   &lt;-- {"type":"CLOSE"}
  Exception in thread "Thread-4" java.lang.NoSuchMethodError: org.codehaus.jackson.JsonNode.has(Ljava/lang/String;)Z
      at su.litvak.chromecast.api.v2.Channel$ReadThread.run(Channel.java:127)
  2015-12-15 19:14:38,771 DEBUG [sender-7hhge79m75 PING] su.litvak.chromecast.api.v2.Channel -   --> {"type":"StandardMessage$Ping"}</p>
  
  <p>I have got an answer for the code. So I will answer my own question.</p>
  
  <p>Yes it is possible but not officially supported by Google. The problem with the code above came from an old jackson parser that I used. </p>
  
  <p>The above projects works fine atleast for our usecase. We are thinking of expanding it.</p>