Updated Amp to use DNS-SD project and fixed a bug causing repeated status updates...
[stereo.git] / Amp / src / stereo / player / Main.java
blob76e07f7ce0ec39e4a109ab8e3b2a8e67442be67d
1 package stereo.player;
3 import java.util.Set;
5 import stereo.dnssd.DNSSDProvider.Service;
7 import com.apple.dnssd.DNSSDException;
9 public class Main {
11 public static void main(String args[]) throws InterruptedException, DNSSDException {
13 String host = null;
14 int port = 3689;
16 for (int i = 0; i < args.length; i++) {
17 if (args[i].equals("--host") || args[i].equals("-h")) {
18 if (i+1 < args.length) {
19 host = args[i+1];
20 i++;
23 else if (args[i].equals("--port") || args[i].equals("-p")) {
24 if (i+1 < args.length) {
25 port = Integer.parseInt(args[i+1]);
26 i++;
31 if (host == null) {
32 System.out.println("Available stereo servers:");
34 Set<Service> services = stereo.dnssd.DNSSD.impl().browse("_touch-able._tcp.");
35 for (Service service: services) {
36 System.out.printf("\t%s:%d (%s)\n", service.host, service.port, service.get("CtlN"));
38 switch (services.size()) {
39 case 1:
40 Service service = services.iterator().next();
41 host = service.host;
42 port = service.port;
43 System.out.println("Connecting...");
44 break;
45 case 0:
46 System.out.println("\tnone");
47 break;
48 default:
49 System.out.println("Please select a server ("+services.size()+")");
53 if (host != null) {
54 StereoAmp amp = new StereoAmp(host, port);
55 amp.start();
56 amp.listen();