-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoundDriverV1.java
86 lines (73 loc) · 2.67 KB
/
SoundDriverV1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* To change this template, choose Tools | Templates
*
* @author Mr. Gonzalez, Nicholas Hernandez, Justin Chen
* @version 1.32 6/2/2015
*/
import java.io.IOException;
import java.io.InputStream;
import javax.sound.sampled.*;
/**
*
* @author bhsjava
*/
public class SoundDriverV1 {
private Clip[] clips;
private int[] framePosition;
private FloatControl gainControl;
public SoundDriverV1(String[] aClips) {
clips = new Clip[aClips.length];
framePosition = new int[aClips.length];
try {
AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
AudioSystem.NOT_SPECIFIED,
16, 2, 4,
AudioSystem.NOT_SPECIFIED, true);
DataLine.Info info = new DataLine.Info(Clip.class, format);
for (int i = 0; i < clips.length; i++) {
//File soundFile = new File(aClips[i]);
//BufferedInputStream bs = new BufferedInputStream(new FileInputStream(soundFile));
//URL inS = ;
AudioInputStream soundIn = AudioSystem.getAudioInputStream(this.getClass().getResource(aClips[i]));
clips[i] = (Clip) AudioSystem.getLine(info);
//clips[i] = AudioSystem.
clips[i].open(soundIn);
gainControl = (FloatControl) clips[i].getControl(FloatControl.Type.MASTER_GAIN);
}
//System.out.println("Audio File Loaded");
} catch (UnsupportedAudioFileException ex) {
System.out.println("Unsupported Audio File");
} catch (LineUnavailableException ex) {
System.out.println("Line Unavailable");
} catch (IOException ex) {
System.out.println("IO Error" + ex);
}
}
public void play(int value) {
clips[value].stop();
clips[value].setFramePosition(0);
clips[value].start();
}
public void loop(int value) {
clips[value].stop();
clips[value].setFramePosition(0);
clips[value].loop(Clip.LOOP_CONTINUOUSLY);
}
public void stop(int value) {
clips[value].stop();
}
public void pause(int value){
framePosition[value] = clips[value].getFramePosition();
clips[value].stop();
}
public void resume(int value){
clips[value].setFramePosition(framePosition[value]);
clips[value].start();
}
public boolean isPlaying(int value){
return clips[value].isRunning();
}
public void setVolume(float volume) {
//gainControl.setValue(volume);
}
}