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.replay.mediaplayer;
025:
026: import org.apache.log4j.Logger;
027:
028: import javax.media.ControllerClosedEvent;
029: import javax.media.ControllerErrorEvent;
030: import javax.media.ControllerEvent;
031: import javax.media.ControllerListener;
032: import javax.media.EndOfMediaEvent;
033: import javax.media.Player;
034: import javax.media.PrefetchCompleteEvent;
035: import javax.media.RealizeCompleteEvent;
036: import javax.media.SizeChangeEvent;
037:
038: /**
039: * Player class abstracts and controls all media players.
040: *
041: * @author Oliver Specht
042: * @version $revision$
043: */
044: public abstract class MediaPlayer implements ControllerListener {
045: /** The Logger */
046: Logger LOG = Logger.getLogger(MediaPlayer.class);
047:
048: /** The file to be replayed */
049: String filename = null;
050: boolean isRunning;
051:
052: /**
053: * Creates a new MediaPlayer
054: */
055: protected MediaPlayer() {
056: }
057:
058: /**
059: * Creates a new MediaPlayer with the given filename
060: *
061: * @param filename tthe file to be replayed
062: */
063: protected MediaPlayer(String filename) {
064: this ();
065: this .filename = filename;
066: init();
067: }
068:
069: /**
070: * Initializes the player including catching all exceptions.
071: */
072: protected abstract void init();
073:
074: /**
075: * Returns the filename of the file to be replayed
076: *
077: * @return String the filename
078: */
079: public String getFilename() {
080: return this .filename;
081: }
082:
083: /**
084: * Return the player this player uses.
085: *
086: * @return {@link Player}
087: */
088: public abstract Player getPlayer();
089:
090: /**
091: * {@inheritDoc}
092: */
093: public void controllerUpdate(ControllerEvent event) {
094: /**
095: * If player has been realized, add its visual component to the main panel and prefetch
096: * the player.
097: */
098: if (event instanceof RealizeCompleteEvent) {
099: processRealizeCompleteEvent(event);
100:
101: /**
102: * If the replay of the media has ended, just log...
103: */
104: } else if (event instanceof EndOfMediaEvent) {
105: //LOG.info ("EndOfMediaEvent: " + event);
106:
107: /**
108: * If an error occurred, log and set player to null
109: */
110: } else if (event instanceof ControllerErrorEvent) {
111: //LOG.info ("An error occurred: " + event);
112:
113: /**
114: * If prefetching is complete, resize the window and start the replay
115: */
116: } else if (event instanceof PrefetchCompleteEvent) {
117: processPrefetchCompleteEvent(event);
118: } else if (event instanceof SizeChangeEvent) {
119: ;
120: } else if (event instanceof ControllerClosedEvent) {
121: ;
122: }
123: }
124:
125: /**
126: * Called when the prefetching is complete
127: *
128: * @param event {@link ControllerEvent}
129: */
130: protected abstract void processPrefetchCompleteEvent(
131: ControllerEvent event);
132:
133: /**
134: * Called when ralizing has been completed
135: *
136: * @param event {@link ControllerEvent}
137: */
138: protected abstract void processRealizeCompleteEvent(
139: ControllerEvent event);
140:
141: /**
142: * Called when the media has ended
143: *
144: * @param event {@link ControllerEvent}
145: */
146: protected abstract void processEndOfMediaEvent(ControllerEvent event);
147:
148: /**
149: * True, if the player is running
150: *
151: * @return boolean true, if the player is running
152: */
153: public abstract boolean isRunning();
154: }
|