From 0ac57b6bd8ace51e736279e68f06eb68d0fa9139 Mon Sep 17 00:00:00 2001 From: "stephen@sfnelson.org" Date: Fri, 30 Jan 2009 02:54:09 +0000 Subject: [PATCH] Spike solution using sockets for changing volume git-svn-id: https://stereo.googlecode.com/svn/trunk@393 c67ee986-0855-0410-825f-15918b819f62 --- MemphisDJ/src/music/VolumeControl.java | 36 ++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/MemphisDJ/src/music/VolumeControl.java b/MemphisDJ/src/music/VolumeControl.java index 9a52e0f..7d4785d 100644 --- a/MemphisDJ/src/music/VolumeControl.java +++ b/MemphisDJ/src/music/VolumeControl.java @@ -1,14 +1,32 @@ package music; -import java.net.URL; +import java.io.IOException; +import java.io.PrintWriter; +import java.net.Socket; +import java.net.UnknownHostException; import java.util.Scanner; +import javax.net.SocketFactory; + + public class VolumeControl implements interfaces.VolumeControl { private int volume; public int getVolume() { + try { + Socket sock = SocketFactory.getDefault().createSocket("localhost", 50123); + new PrintWriter(sock.getOutputStream()).append("get\n").flush(); + this.volume = new Scanner(sock.getInputStream()).nextInt(); + } catch (UnknownHostException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + /* URL url = DJ.class.getResource("getvolume.sh"); try { @@ -25,13 +43,26 @@ public class VolumeControl implements interfaces.VolumeControl { } catch (Exception e) { System.err.println("set volume failed"); e.printStackTrace(); - } + }*/ return this.volume; } public void setVolume(int volume) { this.volume = volume; + + try { + Socket sock = SocketFactory.getDefault().createSocket("localhost", 50123); + new PrintWriter(sock.getOutputStream()).append(this.volume + "\n").flush(); + } catch (UnknownHostException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + /* URL url = DJ.class.getResource("setvolume.sh"); try { @@ -45,6 +76,7 @@ public class VolumeControl implements interfaces.VolumeControl { System.err.println("set volume failed"); e.printStackTrace(); } + */ } } -- 2.11.4.GIT