View Javadoc

1   /*
2    * This file is part of NetPisteur.
3    * 
4    * Copyright 2001-2002 : Olivier CORNEC, David BOUANCHEAU, Loic LOPEZ,
5    *                       Gaetan BOUDARD, Mael LE LANNOU, Julien ROBINEAU
6    * 
7    * Copyright 2002-2003 : Olivier BRIENS, Simon DEZE, Florence FRIGOULT,
8    *                       Olivier JOURNEAULT, Francois MARTINIER, Damien RAUDE-MORVAN
9    * 
10   * Copyright 2004-2007 : Damien RAUDE-MORVAN
11   * 
12   * NetPisteur is free software; you can redistribute it and/or modify
13   * it under the terms of the GNU General Public License as published by
14   * the Free Software Foundation; either version 2 of the License, or
15   * (at your option) any later version.
16   *
17   * NetPisteur is distributed in the hope that it will be useful,
18   * but WITHOUT ANY WARRANTY; without even the implied warranty of
19   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20   * GNU General Public License for more details.
21   *
22   * You should have received a copy of the GNU General Public License
23   * along with NetPisteur; if not, write to the Free Software
24   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
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  	// class variable
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  }