René Malmgren
René Malmgren

Reputation: 31

Java API for ChromeCast

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.

So far I have found this project:

https://github.com/vitalidze/chromecast-java-api-v2

But so far I have not been able to get it working.

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.

My testcode:

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();
    }
}

The result from the log:

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 - <-- {"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"}

I have got an answer for the code. So I will answer my own question.

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.

The above projects works fine atleast for our usecase. We are thinking of expanding it.

Upvotes: 3

Views: 4189

Answers (2)

otaviodecampos
otaviodecampos

Reputation: 1894

You have same dependency with different versions in your project. Probably you have two projects has Jackson dependency, but in different versions.

NoSuchMethodError: org.codehaus.jackson.JsonNode.has(Ljava/lang/String;)

About chromecast-java-api-v2, its works very fine, but you need a media server, then the chromecast-java-api-v2 you request to chromecast play your files with a url.

Upvotes: 0

Ali Naddaf
Ali Naddaf

Reputation: 19044

No, you need to use the Cast SDK that is available on Android, iOS and Chrome. Alternative approach is to use the cast device using pure media router APIs which again requires an Android framework, etc.

Upvotes: 3

Related Questions