Ignore rules for git users
[stereo.git] / MemphisDJ / src / music / VolumeControl.java
blobaa5140fd601926869dbf0da050a0b7a34760cee8
1 package music;
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.net.ConnectException;
6 import java.net.Socket;
7 import java.net.UnknownHostException;
8 import java.util.Scanner;
10 import javax.net.SocketFactory;
13 public class VolumeControl implements interfaces.VolumeControl {
15 private int volume;
17 public int getVolume() {
19 try {
20 Socket sock = SocketFactory.getDefault().createSocket("localhost", 50123);
21 new PrintWriter(sock.getOutputStream()).append("get\n").flush();
22 this.volume = new Scanner(sock.getInputStream()).nextInt();
23 } catch (UnknownHostException e) {
24 // TODO Auto-generated catch block
25 e.printStackTrace();
26 } catch (ConnectException e) {
27 System.err.println("warning: volume not available");
28 } catch (IOException e) {
29 // TODO Auto-generated catch block
30 e.printStackTrace();
33 URL url = DJ.class.getResource("getvolume.sh");
35 try {
36 System.out.println("getting volume");
37 Process p = Runtime.getRuntime().exec(
38 "bash " + url.getFile());
39 for (Scanner sc = new Scanner(p.getErrorStream()); sc.hasNextLine();) {
40 System.out.println(sc.nextLine());
42 Scanner sc = new Scanner(p.getInputStream());
43 if (sc.hasNextInt()) {
44 this.volume = sc.nextInt();
46 } catch (Exception e) {
47 System.err.println("set volume failed");
48 e.printStackTrace();
49 }*/
51 return this.volume;
54 public void setVolume(int volume) {
55 this.volume = volume;
57 try {
58 Socket sock = SocketFactory.getDefault().createSocket("localhost", 50123);
59 new PrintWriter(sock.getOutputStream()).append(this.volume + "\n").flush();
60 } catch (UnknownHostException e) {
61 // TODO Auto-generated catch block
62 e.printStackTrace();
63 } catch (IOException e) {
64 // TODO Auto-generated catch block
65 e.printStackTrace();
69 URL url = DJ.class.getResource("setvolume.sh");
71 try {
72 System.out.println("setting volume to " + volume);
73 Process p = Runtime.getRuntime().exec(
74 "bash " + url.getFile() + " " + volume);
75 for (Scanner sc = new Scanner(p.getErrorStream()); sc.hasNextLine();) {
76 System.out.println(sc.nextLine());
78 } catch (Exception e) {
79 System.err.println("set volume failed");
80 e.printStackTrace();