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
{
17 public int getVolume() {
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
26 } catch (ConnectException e
) {
27 System
.err
.println("warning: volume not available");
28 } catch (IOException e
) {
29 // TODO Auto-generated catch block
33 URL url = DJ.class.getResource("getvolume.sh");
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");
54 public void setVolume(int volume
) {
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
63 } catch (IOException e
) {
64 // TODO Auto-generated catch block
69 URL url = DJ.class.getResource("setvolume.sh");
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");