Added functionality for getting system volume on BSD and linux
[stereo.git] / MemphisDJ / src / music / VolumeControl.java
blob0e9af09a21caeb0879e7f204cf818949fc200395
1 package music;
3 import java.io.IOException;
4 import java.net.URL;
5 import java.util.Scanner;
7 public class VolumeControl implements interfaces.VolumeControl {
9 private int volume;
11 public int getVolume() {
13 URL url = DJ.class.getResource("getvolume.sh");
15 try {
16 System.out.println("getting volume");
17 Process p = Runtime.getRuntime().exec(
18 "bash " + url.getFile());
19 for (Scanner sc = new Scanner(p.getErrorStream()); sc.hasNextLine();) {
20 System.out.println(sc.nextLine());
22 Scanner sc = new Scanner(p.getInputStream());
23 if (sc.hasNextInt()) {
24 this.volume = sc.nextInt();
26 } catch (IOException e) {
27 System.err.println("set volume failed");
28 e.printStackTrace();
31 return this.volume;
34 public void setVolume(int volume) {
35 this.volume = volume;
36 URL url = DJ.class.getResource("setvolume.sh");
38 try {
39 System.out.println("setting volume to " + volume);
40 Process p = Runtime.getRuntime().exec(
41 "bash " + url.getFile() + " " + volume);
42 for (Scanner sc = new Scanner(p.getErrorStream()); sc.hasNextLine();) {
43 System.out.println(sc.nextLine());
45 } catch (IOException e) {
46 System.err.println("set volume failed");
47 e.printStackTrace();