annotate kopieckreta/src/wavResource.java @ 7:bb29f1c89c99

immposiblerush-0.230919-0_PKG
author prymula <prymula76@outlook.com>
date Thu, 01 Feb 2024 21:49:30 +0100
parents 2787f5e749ae
children 489244127359
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
prymula <prymula76@outlook.com>
parents:
diff changeset
1
prymula <prymula76@outlook.com>
parents:
diff changeset
2 package src;
prymula <prymula76@outlook.com>
parents:
diff changeset
3
prymula <prymula76@outlook.com>
parents:
diff changeset
4 import java.io.IOException;
prymula <prymula76@outlook.com>
parents:
diff changeset
5 import java.io.InputStream;
prymula <prymula76@outlook.com>
parents:
diff changeset
6 import java.io.PrintStream;
prymula <prymula76@outlook.com>
parents:
diff changeset
7 import java.io.BufferedReader;
prymula <prymula76@outlook.com>
parents:
diff changeset
8 import java.io.InputStreamReader;
prymula <prymula76@outlook.com>
parents:
diff changeset
9 import java.io.BufferedInputStream;
prymula <prymula76@outlook.com>
parents:
diff changeset
10 import java.io.FileInputStream;
prymula <prymula76@outlook.com>
parents:
diff changeset
11 import java.io.File;
prymula <prymula76@outlook.com>
parents:
diff changeset
12
prymula <prymula76@outlook.com>
parents:
diff changeset
13 import java.util.*;
prymula <prymula76@outlook.com>
parents:
diff changeset
14 import java.lang.*;
prymula <prymula76@outlook.com>
parents:
diff changeset
15
prymula <prymula76@outlook.com>
parents:
diff changeset
16 import javax.sound.sampled.AudioInputStream;
prymula <prymula76@outlook.com>
parents:
diff changeset
17 import javax.sound.sampled.AudioSystem;
prymula <prymula76@outlook.com>
parents:
diff changeset
18 import javax.sound.sampled.Clip;
prymula <prymula76@outlook.com>
parents:
diff changeset
19 import javax.sound.sampled.LineUnavailableException;
prymula <prymula76@outlook.com>
parents:
diff changeset
20
prymula <prymula76@outlook.com>
parents:
diff changeset
21
prymula <prymula76@outlook.com>
parents:
diff changeset
22 public class wavResource {
prymula <prymula76@outlook.com>
parents:
diff changeset
23 AudioInputStream ais;
prymula <prymula76@outlook.com>
parents:
diff changeset
24 Clip clip;
prymula <prymula76@outlook.com>
parents:
diff changeset
25 boolean running=false;
prymula <prymula76@outlook.com>
parents:
diff changeset
26 public boolean PlayFlag=false;
prymula <prymula76@outlook.com>
parents:
diff changeset
27 final int BUFFER_SIZE=128000;
prymula <prymula76@outlook.com>
parents:
diff changeset
28
prymula <prymula76@outlook.com>
parents:
diff changeset
29 public void wavResource()
prymula <prymula76@outlook.com>
parents:
diff changeset
30 {
prymula <prymula76@outlook.com>
parents:
diff changeset
31
prymula <prymula76@outlook.com>
parents:
diff changeset
32 }
prymula <prymula76@outlook.com>
parents:
diff changeset
33 public synchronized void play(final String filename){
prymula <prymula76@outlook.com>
parents:
diff changeset
34 new Thread(new Runnable() {
prymula <prymula76@outlook.com>
parents:
diff changeset
35 public void run() {
prymula <prymula76@outlook.com>
parents:
diff changeset
36 try{
prymula <prymula76@outlook.com>
parents:
diff changeset
37 InputStream is = getClass().getResourceAsStream(filename);
prymula <prymula76@outlook.com>
parents:
diff changeset
38 InputStream bIn = new BufferedInputStream(is);
prymula <prymula76@outlook.com>
parents:
diff changeset
39 ais = AudioSystem.getAudioInputStream(bIn);
prymula <prymula76@outlook.com>
parents:
diff changeset
40
prymula <prymula76@outlook.com>
parents:
diff changeset
41 if (PlayFlag) { // to musi być
prymula <prymula76@outlook.com>
parents:
diff changeset
42 clip = AudioSystem.getClip();
prymula <prymula76@outlook.com>
parents:
diff changeset
43 clip.open(ais);
prymula <prymula76@outlook.com>
parents:
diff changeset
44 clip.start();
prymula <prymula76@outlook.com>
parents:
diff changeset
45 ais.mark(BUFFER_SIZE); // po odkomentowaniu clip ustawiony na poczatek
prymula <prymula76@outlook.com>
parents:
diff changeset
46 ais.reset();
prymula <prymula76@outlook.com>
parents:
diff changeset
47 PlayFlag=false;
prymula <prymula76@outlook.com>
parents:
diff changeset
48 }
prymula <prymula76@outlook.com>
parents:
diff changeset
49 } catch (Exception e) {
prymula <prymula76@outlook.com>
parents:
diff changeset
50 e.printStackTrace();
prymula <prymula76@outlook.com>
parents:
diff changeset
51 } //catch (IOException e){
prymula <prymula76@outlook.com>
parents:
diff changeset
52
prymula <prymula76@outlook.com>
parents:
diff changeset
53
prymula <prymula76@outlook.com>
parents:
diff changeset
54 // }
prymula <prymula76@outlook.com>
parents:
diff changeset
55
prymula <prymula76@outlook.com>
parents:
diff changeset
56 }
prymula <prymula76@outlook.com>
parents:
diff changeset
57 }).start();
prymula <prymula76@outlook.com>
parents:
diff changeset
58 }
prymula <prymula76@outlook.com>
parents:
diff changeset
59 public void stop(){
prymula <prymula76@outlook.com>
parents:
diff changeset
60 if (clip != null) {
prymula <prymula76@outlook.com>
parents:
diff changeset
61 clip.stop();
prymula <prymula76@outlook.com>
parents:
diff changeset
62 clip.drain();
prymula <prymula76@outlook.com>
parents:
diff changeset
63 clip.close();
prymula <prymula76@outlook.com>
parents:
diff changeset
64 PlayFlag=false;
prymula <prymula76@outlook.com>
parents:
diff changeset
65 //clip.flush();
prymula <prymula76@outlook.com>
parents:
diff changeset
66 //clip.setFramePosition(0);
prymula <prymula76@outlook.com>
parents:
diff changeset
67 //System.out.println("Jestem w stopOk");
prymula <prymula76@outlook.com>
parents:
diff changeset
68 }
prymula <prymula76@outlook.com>
parents:
diff changeset
69 }
prymula <prymula76@outlook.com>
parents:
diff changeset
70
prymula <prymula76@outlook.com>
parents:
diff changeset
71 }