0
|
1
|
|
2 package src;
|
|
3
|
|
4 import java.io.IOException;
|
|
5 import java.io.InputStream;
|
|
6 import java.io.PrintStream;
|
|
7 import java.io.BufferedReader;
|
|
8 import java.io.InputStreamReader;
|
|
9 import java.io.BufferedInputStream;
|
|
10 import java.io.FileInputStream;
|
|
11 import java.io.File;
|
|
12
|
|
13 import java.util.*;
|
|
14 import java.lang.*;
|
|
15
|
|
16 import javax.sound.sampled.AudioInputStream;
|
|
17 import javax.sound.sampled.AudioSystem;
|
|
18 import javax.sound.sampled.Clip;
|
|
19 import javax.sound.sampled.LineUnavailableException;
|
|
20
|
|
21
|
|
22 public class wavResource {
|
|
23 AudioInputStream ais;
|
|
24 Clip clip;
|
|
25 boolean running=false;
|
|
26 public boolean PlayFlag=false;
|
|
27 final int BUFFER_SIZE=128000;
|
|
28
|
|
29 public void wavResource()
|
|
30 {
|
|
31
|
|
32 }
|
|
33 public synchronized void play(final String filename){
|
|
34 new Thread(new Runnable() {
|
|
35 public void run() {
|
|
36 try{
|
|
37 InputStream is = getClass().getResourceAsStream(filename);
|
|
38 InputStream bIn = new BufferedInputStream(is);
|
|
39 ais = AudioSystem.getAudioInputStream(bIn);
|
|
40
|
23
|
41 if (PlayFlag) { // to musi byc
|
0
|
42 clip = AudioSystem.getClip();
|
|
43 clip.open(ais);
|
|
44 clip.start();
|
|
45 ais.mark(BUFFER_SIZE); // po odkomentowaniu clip ustawiony na poczatek
|
|
46 ais.reset();
|
|
47 PlayFlag=false;
|
|
48 }
|
|
49 } catch (Exception e) {
|
|
50 e.printStackTrace();
|
|
51 } //catch (IOException e){
|
|
52
|
|
53
|
|
54 // }
|
|
55
|
|
56 }
|
|
57 }).start();
|
|
58 }
|
|
59 public void stop(){
|
|
60 if (clip != null) {
|
|
61 clip.stop();
|
|
62 clip.drain();
|
|
63 clip.close();
|
|
64 PlayFlag=false;
|
|
65 //clip.flush();
|
|
66 //clip.setFramePosition(0);
|
|
67 //System.out.println("Jestem w stopOk");
|
|
68 }
|
|
69 }
|
|
70
|
|
71 }
|