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 package com.drazzib.netpisteur.ui.render;
28
29 import java.applet.Applet;
30 import java.applet.AudioClip;
31 import java.net.URL;
32 import java.util.ArrayList;
33
34 import org.apache.commons.logging.Log;
35 import org.apache.commons.logging.LogFactory;
36
37 /**
38 * This class is used to play sound found in HTML page with courtesy of Applet
39 * class
40 */
41 public class AudioPlayer {
42
43 private static Log log = LogFactory.getLog(AudioPlayer.class);
44
45
46 AudioClip _clip;
47
48 public static ArrayList mySounds = new ArrayList();
49
50 public static void reset() {
51 for (int i = 0; i < mySounds.size(); i++) {
52 ((AudioPlayer) mySounds.get(i)).stop();
53 }
54 mySounds.clear();
55 }
56
57 /**
58 * Constructor
59 */
60 public AudioPlayer(URL url, boolean loop) {
61 this._clip = Applet.newAudioClip(url);
62 log.debug("URL:"+url.toString());
63 if (loop == false) {
64 this._clip.play();
65 log.debug("AP: Lecture du fichier 1 fois");
66 } else {
67 this._clip.loop();
68 log.debug("AP: Lecture en boucle");
69 }
70 mySounds.add(this);
71 }
72
73 /**
74 * to see in loop the sound
75 */
76 public void loop() {
77 this._clip.loop();
78 log.debug("AP: Lecture en boucle (loop)");
79 }
80
81 /**
82 * stop reading of the sound
83 */
84 public void stop() {
85 this._clip.stop();
86 log.debug("AP: Stop la lecture");
87 }
88
89 /**
90 * read once the sound
91 */
92 public void play() {
93 this._clip.play();
94 log.debug("AP: Lecture 1 fois (play)");
95 }
96 }