001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: /* PHL Software License, Version 1.0
025: *
026: * Copyright (c) 2002 Mathematics & Computer Science Department,
027: * Ludwigsburg University of Education. All rights reserved.
028: *
029: * Redistribution and use in source and binary forms, with or without
030: * modification, are permitted provided that the following conditions
031: * are met:
032: *
033: * 1. Redistributions of source code must retain the above copyright notice,
034: * this list of conditions and the following disclaimer.
035: *
036: * 2. Redistributions in binary form must reproduce the above copyright
037: * notice, this list of conditions and the following disclaimer in the
038: * documentation and/or other materials provided with the distribution.
039: *
040: * 3. The end-user documentation included with the redistribution, if any,
041: * must include the following acknowledgment:
042: * "This product includes software developed by the Mathematics &
043: * Computer Science Department, Ludwigsburg University of Education
044: * (http://www.ph-ludwigsburg.de/mathematik/)."
045: * Alternately, this acknowledgment may appear in the software itself,
046: * if and wherever such third-party acknowledgments normally appear.
047: *
048: * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
049: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
050: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
051: * THE MATHEMATICS & COMPUTER SCIENCE DEPARTMENT, LUDWIGSBURG UNIVERSITY OF
052: * EDUCATION, OR THEIR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
053: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
054: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
055: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
056: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
057: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
058: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
059: */
060: package jacareto.toolkit;
061:
062: import java.applet.Applet;
063: import java.applet.AudioClip;
064:
065: import java.net.MalformedURLException;
066: import java.net.URL;
067:
068: import java.util.Hashtable;
069:
070: /**
071: * An audio clip manager offers methods to load audio clips. All loaded audio clips will be
072: * "cached".
073: *
074: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
075: * @version 1.0
076: */
077: public class AudioClipManager {
078: /** Hashtable of all loaded audio clips (Maps filenames to audio clips). */
079: private static Hashtable audioClips;
080:
081: static {
082: audioClips = new Hashtable();
083: }
084:
085: /**
086: * Returns the audio clip stored in the file with the given file name. If the audio clip has
087: * already been loaded, the cached one will be returned.
088: *
089: * @param filename DOCUMENT ME!
090: *
091: * @return DOCUMENT ME!
092: *
093: * @throws MalformedURLException if an url cannot be constructed from the given filename
094: */
095: public static AudioClip getAudioClip(String filename)
096: throws MalformedURLException {
097: if (audioClips.containsKey(filename)) {
098: return (AudioClip) audioClips.get(filename);
099: } else {
100: URL url = new URL("file:" + filename);
101: AudioClip audioClip = Applet.newAudioClip(url);
102: audioClips.put(filename, audioClip);
103:
104: return audioClip;
105: }
106: }
107: }
|