summaryrefslogtreecommitdiffstats
path: root/khtml/java/org/kde/kjas/server/KJASAudioClip.java
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch)
tree5ac38a06f3dde268dc7927dc155896926aaf7012 /khtml/java/org/kde/kjas/server/KJASAudioClip.java
downloadtdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz
tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'khtml/java/org/kde/kjas/server/KJASAudioClip.java')
-rw-r--r--khtml/java/org/kde/kjas/server/KJASAudioClip.java98
1 files changed, 98 insertions, 0 deletions
diff --git a/khtml/java/org/kde/kjas/server/KJASAudioClip.java b/khtml/java/org/kde/kjas/server/KJASAudioClip.java
new file mode 100644
index 000000000..3a40cf6e0
--- /dev/null
+++ b/khtml/java/org/kde/kjas/server/KJASAudioClip.java
@@ -0,0 +1,98 @@
+package org.kde.kjas.server;
+
+import java.applet.*;
+import java.net.*;
+import java.util.*;
+/**
+* Background Audioclip Loader and Player.
+* @author Till Krech (till@snafu.de)
+*/
+public class KJASAudioClip implements AudioClip
+{
+ private AudioClip theClip;
+ private final static int PLAYING = 1;
+ private final static int LOOPING = 2;
+ private final static int STOPPED = 3;
+ private int state;
+ private static Hashtable cache = new Hashtable();
+
+ /**
+ * creates a new Audioclip.
+ * The AudioClip is loaded in background. The Constructor returns immediately.
+ */
+ public KJASAudioClip(URL url)
+ {
+ state = STOPPED;
+ theClip = (AudioClip)cache.get(url);
+ if (theClip == null) {
+ final URL theUrl = url;
+
+ new Thread
+ (
+ new Runnable() {
+ public void run() {
+ theClip = java.applet.Applet.newAudioClip(theUrl);
+ cache.put(theUrl, theClip);
+ if (state == LOOPING) {
+ theClip.loop();
+ } else if (state == PLAYING) {
+ theClip.play();
+ }
+ }
+ }, "AudioClipLoader " + url.getFile()
+ ).start();
+ }
+ }
+
+ /**
+ * play continously when the clip is loaded
+ */
+ public void loop()
+ {
+ state = LOOPING;
+ if (theClip != null) {
+ new Thread
+ (
+ new Runnable() {
+ public void run() {
+ theClip.loop();
+ }
+ }, "AudioClipLooper "
+ ).start();
+ }
+ }
+
+ /**
+ * play when the clip is loaded
+ */
+ public void play()
+ {
+ state = PLAYING;
+ if (theClip != null) {
+ new Thread
+ (
+ new Runnable() {
+ public void run() {
+ theClip.play();
+ }
+ }, "AudioClipPlayer "
+ ).start();
+ }
+ }
+
+ /**
+ * stop the clip
+ */
+ public void stop()
+ {
+ state = STOPPED;
+ if (theClip != null) {
+ theClip.stop();
+ }
+ }
+
+ public void finalize() {
+ stop();
+ }
+}
+