blob: 5db3e98312f08ba7f40cab2edaa42cdb81227b99 (
plain)
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
|
package src;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.File;
import java.util.*;
import java.lang.*;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
public class wavResource {
AudioInputStream ais;
Clip clip;
boolean running=false;
public boolean PlayFlag=false;
final int BUFFER_SIZE=128000;
public void wavResource()
{
}
public synchronized void play(final String filename){
new Thread(new Runnable() {
public void run() {
try{
InputStream is = getClass().getResourceAsStream(filename);
InputStream bIn = new BufferedInputStream(is);
ais = AudioSystem.getAudioInputStream(bIn);
if (PlayFlag) { // to musi byc
clip = AudioSystem.getClip();
clip.open(ais);
clip.start();
ais.mark(BUFFER_SIZE); // po odkomentowaniu clip ustawiony na poczatek
ais.reset();
PlayFlag=false;
}
} catch (Exception e) {
e.printStackTrace();
} //catch (IOException e){
// }
}
}).start();
}
public void stop(){
if (clip != null) {
clip.stop();
clip.drain();
clip.close();
PlayFlag=false;
//clip.flush();
//clip.setFramePosition(0);
//System.out.println("Jestem w stopOk");
}
}
}
|