summaryrefslogtreecommitdiff
path: root/src/wavResource.java
diff options
context:
space:
mode:
authorPrzemyslaw <prymula76@outlook.com>2024-04-01 09:02:22 +0200
committerPrzemyslaw <prymula76@outlook.com>2024-04-01 09:02:22 +0200
commitd8afc9f5c2aa97a96ca326c0178a7fc9577afaaf (patch)
tree730acbaff01acd5ebed98a7c6ee831ccb731706e /src/wavResource.java
Init
Diffstat (limited to 'src/wavResource.java')
-rw-r--r--src/wavResource.java71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/wavResource.java b/src/wavResource.java
new file mode 100644
index 0000000..5db3e98
--- /dev/null
+++ b/src/wavResource.java
@@ -0,0 +1,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");
+ }
+ }
+
+}