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;
025:
026: import jacareto.record.VideoClipRecordable;
027: import jacareto.replay.event.ReplayEvent;
028: import jacareto.replay.event.ReplayListener;
029: import jacareto.replay.mediaplayer.DefaultMediaPlayerFactory;
030: import jacareto.replay.mediaplayer.VideoPlayer;
031: import jacareto.struct.StructureElement;
032: import jacareto.system.Environment;
033: import jacareto.track.block.BlockType;
034:
035: import org.apache.log4j.Logger;
036:
037: import javax.media.Time;
038:
039: /**
040: * A replayer which is responsible for video clips. The video clips will be played back during the
041: * session.
042: *
043: * @author Oliver Specht
044: * @version $revision$
045: */
046: public class VideoClipReplayer extends Replayer implements Runnable,
047: ReplayListener {
048: /** The Logger */
049: private static final Logger LOG = Logger
050: .getLogger(VideoClipReplayer.class);
051:
052: /** The filename of the video clip. */
053: private String filename;
054:
055: /** The VideoPlayer */
056: VideoPlayer player;
057:
058: /**
059: * Creates a new video clip replayer
060: *
061: * @param env
062: * @param replay
063: */
064: public VideoClipReplayer(Environment env, Replay replay) {
065: super (env, replay);
066: }
067:
068: public boolean handlesElement(StructureElement element) {
069: return false;
070:
071: // return (element != null) && (element instanceof VideoClipRecordable);
072: }
073:
074: public boolean replay(StructureElement element) {
075: VideoClipRecordable recordable = (VideoClipRecordable) element;
076: filename = recordable.getFilename();
077:
078: try {
079: player = (VideoPlayer) DefaultMediaPlayerFactory
080: .getInstance().createPlayer(BlockType.VIDEO,
081: filename);
082: player.replay();
083: } catch (Exception e) {
084: LOG.error(getLanguage().getString(
085: "Replayers.VideoClipReplayer.Error.Play"));
086: LOG.error("Error in VideoPlayer!");
087: e.printStackTrace();
088:
089: return false;
090: }
091:
092: return true;
093: }
094:
095: /**
096: * {@inheritDoc}
097: */
098: public void run() {
099: }
100:
101: /**
102: * Returns the current media time
103: *
104: * @return long media time in ms
105: */
106: public long getMediaTime() {
107: return this .player.getPlayer().getMediaNanoseconds() / 1000000;
108: }
109:
110: /**
111: * True if the player is running
112: *
113: * @return boolean
114: */
115: public boolean isRunning() {
116: return this .player.isRunning();
117: }
118:
119: public void replayStateChanged(ReplayEvent event) {
120: if (event.getID() == ReplayEvent.STOPPED) {
121: this .player.getPlayer().stop();
122: this .player.getPlayer().setMediaTime(new Time(0.0));
123: } else if (event.getID() == ReplayEvent.PAUSED) {
124: this.player.getPlayer().stop();
125: }
126: }
127: }
|