问题描述
是否可以使用标准(台式机)Java连接到ChromeCast。我正在寻找一种自动化测试的方法,并希望CC:s自动播放视频。
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:
但是到目前为止,我还无法使其正常工作。
But so far I have not been able to get it working.
使用mDNS可以很好地找到Chromecast,但是当我尝试连接到Chromecast时,我刚刚与CC取得联系。
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.
我的测试代码:
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();
}
}
日志结果:
2015-12-15 19:14:37,727调试[main] su.litvak.chromecast.api.v2.Channel--> { type: StandardMessage $ Ping}
2015-12-15 19:14:37,769调试[main] su.litvak.chromecast.api.v2.Channel--> { type: StandardMessage $ Connect, origin:{} }
2015-12-15 19:14:37,794调试[main] su.litvak.chromecast.api.v2.Channel--> { type: StandardRequest $ Status, requestId:1 }
2015-12-15 19:14:37,802调试[线程4] su.litvak.chromecast.api.v2.Channel-<-{ type: CLOSE}
线程 Thread-4中的异常java.lang.NoSuchMethodError:org.codehaus.jackson.JsonNode.has(Ljava / lang / String;)Z
在su.litvak.chromecast.api.v2.Channel $ ReadThread .run(Channel.java:127)
2015-12-15 19:14:38,771调试[sender-7hhge79m75 PING] su.litvak.chromecast.api.v2.Channel--> { type: StandardMessage $ Ping}
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.
是的,虽然有可能,但未得到Google的正式支持。上面代码的问题来自于我使用的旧的Jackson解析器。
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.
推荐答案
否,您需要使用Android,iOS和Chrome上可用的Cast SDK 。另一种方法是通过纯媒体路由器API使用Cast设备,这又需要Android框架等。
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.
这篇关于ChromeCast的Java API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!