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: package jacareto.record;
025:
026: import jacareto.cleverphl.gui.InfoDialog;
027: import jacareto.system.Environment;
028:
029: import java.io.IOException;
030:
031: import javax.sound.sampled.AudioFileFormat;
032: import javax.sound.sampled.AudioSystem;
033: import javax.sound.sampled.UnsupportedAudioFileException;
034:
035: /**
036: * This class represents an audio clip.
037: *
038: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>, Oliver Specht
039: * @version $revision$
040: */
041: public class AudioClipRecordable extends MediaClipRecordable {
042: /** The duration */
043: private long duration;
044:
045: /**
046: * Creates a new audio clip recordable with no file reference.
047: *
048: * @param env Environment
049: */
050: public AudioClipRecordable(Environment env) {
051: this (env, "");
052: }
053:
054: /**
055: * Creates a new audio clio recordable.
056: *
057: * @param env the environment
058: * @param filename the name of the audio file
059: */
060: public AudioClipRecordable(Environment env, String filename) {
061: super (env);
062: setFilename(filename);
063: determineDuration();
064: }
065:
066: /**
067: * <p>
068: * Only to be used for JUnit tests!
069: * </p>
070: * Creates a new audio clip recordable with default values and no environment. The environment
071: * should be defined with the method {@link
072: * jacareto.system.EnvironmentMember#setEnvironment(Environment)} before environment instances
073: * will be accessed.
074: */
075: public AudioClipRecordable() {
076: this (null);
077: }
078:
079: public boolean determineDuration() {
080: if (!this
081: .getFilename()
082: .equals(
083: getLanguage()
084: .getString(
085: "Recordables.MediaClipRecordable.DefaultFilename"))) {
086: try {
087: AudioFileFormat aff = AudioSystem
088: .getAudioFileFormat(getFile());
089: javax.sound.sampled.AudioFormat format = aff
090: .getFormat();
091:
092: this .setDuration((long) ((aff.getFrameLength() / format
093: .getFrameRate()) * 1000));
094:
095: return true;
096: } catch (UnsupportedAudioFileException e) {
097: InfoDialog dialog;
098: dialog = new InfoDialog(
099: getLanguage().getString(
100: "CleverPHL.InfoDialog.Title"),
101: getLanguage()
102: .getString(
103: "Recordables.MediaClipRecordable.ErrorUnsupportedFileFormat"));
104: dialog.setModal(true);
105: dialog
106: .setTitle(getLanguage()
107: .getString(
108: "Recordables.MediaClipRecordable.ErrorUnsupportedFileFormatTitle"));
109: dialog.setVisible(true);
110:
111: return false;
112: } catch (IOException e) {
113: InfoDialog dialog;
114: dialog = new InfoDialog(
115: getLanguage().getString(
116: "CleverPHL.InfoDialog.Title"),
117: getLanguage()
118: .getString(
119: "Recordables.MediaClipRecordable.ErrorIO"));
120: dialog.setModal(true);
121: dialog
122: .setTitle(getLanguage()
123: .getString(
124: "Recordables.MediaClipRecordable.ErrorIOTitle"));
125: dialog.setVisible(true);
126:
127: return false;
128: }
129: }
130:
131: return false;
132: }
133:
134: /**
135: * Returns the name of this element
136: *
137: * @return the name
138: */
139: public String getElementName() {
140: return getLanguage().getString(
141: "Recordables.AudioClipRecordable.Name");
142: }
143:
144: /**
145: * Returns a description of the Recordable.
146: *
147: * @return the description
148: */
149: public String getElementDescription() {
150: return getLanguage().getString(
151: "Recordables.AudioClipRecordable.Description");
152: }
153:
154: /**
155: * Returns a String which describes the content of the Recordable shortly.
156: *
157: * @return a string with a short description of the Recordable
158: */
159: public String toShortString() {
160: return getElementName() + " (" + filename + ")";
161: }
162:
163: /**
164: * Returns the duration of the audio clip in ms
165: *
166: * @return long the duration
167: */
168: public long getDuration() {
169: return this .duration;
170: }
171:
172: /**
173: * Sets the duration of this element. Is normally called by {@link #determineDuration()}.
174: *
175: * @param duration long the duration of the audio clip
176: */
177: public void setDuration(long duration) {
178: this .duration = duration;
179: }
180:
181: /**
182: * AudioClips don't have a processing time, because they are being replayed by the {@link
183: * jacareto.replay.MediaClipReplayer} which handles the processing etc.
184: *
185: * @return boolean false
186: */
187: public boolean hasProcTime() {
188: return false;
189: }
190: }
|