2002-10-25 20:19:56 +00:00
|
|
|
/*
|
|
|
|
The contents of this file are subject to the THDL Open Community License
|
|
|
|
Version 1.0 (the "License"); you may not use this file except in compliance
|
2002-11-28 16:16:27 +00:00
|
|
|
with the License. You may obtain a copy of the License on the THDL web site
|
2002-10-25 20:19:56 +00:00
|
|
|
(http://www.thdl.org/).
|
|
|
|
|
2002-11-28 16:16:27 +00:00
|
|
|
Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
License for the specific terms governing rights and limitations under the
|
|
|
|
License.
|
2002-10-25 20:19:56 +00:00
|
|
|
|
|
|
|
The Initial Developer of this software is the Tibetan and Himalayan Digital
|
|
|
|
Library (THDL). Portions created by the THDL are Copyright 2001 THDL.
|
2002-11-28 16:16:27 +00:00
|
|
|
All Rights Reserved.
|
2002-10-25 20:19:56 +00:00
|
|
|
|
|
|
|
Contributor(s): ______________________________________.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.thdl.media;
|
|
|
|
|
|
|
|
import java.awt.*;
|
|
|
|
import java.net.*;
|
|
|
|
import quicktime.*;
|
|
|
|
import quicktime.app.*;
|
|
|
|
import quicktime.app.display.*;
|
|
|
|
import quicktime.app.players.*;
|
|
|
|
import quicktime.app.image.*; //required for the QT4JAVA test
|
|
|
|
import quicktime.std.*;
|
|
|
|
import quicktime.std.movies.*;
|
|
|
|
import quicktime.std.movies.media.DataRef;
|
|
|
|
import quicktime.io.*;
|
|
|
|
import quicktime.app.time.*;
|
|
|
|
import quicktime.std.clocks.*;
|
2002-11-28 16:16:27 +00:00
|
|
|
import quicktime.app.QTFactory;
|
2002-10-25 20:19:56 +00:00
|
|
|
|
2002-11-28 16:16:27 +00:00
|
|
|
public class SmartQT4JPlayer extends SmartMoviePanel {
|
2002-10-25 20:19:56 +00:00
|
|
|
|
2002-11-28 16:16:27 +00:00
|
|
|
private myJumpCallBack theJumpper = null;
|
|
|
|
private myRateCallBack theRater = null;
|
|
|
|
private URL mediaUrl = null;
|
|
|
|
private TimeBase myMoviesTimeBase;
|
|
|
|
private QTCanvas canvas;
|
|
|
|
private QTPlayer player;
|
2002-11-02 20:20:30 +00:00
|
|
|
|
2002-11-28 16:16:27 +00:00
|
|
|
//constructor
|
|
|
|
public SmartQT4JPlayer(Container cont, URL mediaURL) {
|
|
|
|
super( new GridLayout() );
|
|
|
|
try {
|
|
|
|
loadMovie(mediaURL);
|
|
|
|
} catch (SmartMoviePanelException smpe) {
|
|
|
|
smpe.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//destructor
|
|
|
|
public void destroy() {
|
|
|
|
if (theJumpper != null)
|
|
|
|
theJumpper.cancelAndCleanup();
|
|
|
|
if(theRater != null)
|
|
|
|
theRater.cancelAndCleanup();
|
2002-10-25 20:19:56 +00:00
|
|
|
|
2002-11-28 16:16:27 +00:00
|
|
|
removeAllAnnotationPlayers();
|
|
|
|
QTSession.close();
|
|
|
|
removeAll();
|
|
|
|
mediaUrl = null;
|
|
|
|
System.out.println("Clean up performed.");
|
|
|
|
}
|
2002-11-02 20:20:30 +00:00
|
|
|
|
2002-10-25 20:19:56 +00:00
|
|
|
//accessors
|
2002-11-02 20:20:30 +00:00
|
|
|
public String getIdentifyingName() {
|
2002-10-25 20:19:56 +00:00
|
|
|
return "Quicktime for Java";
|
|
|
|
}
|
2002-11-02 20:20:30 +00:00
|
|
|
public URL getMediaURL() {
|
|
|
|
return mediaUrl;
|
|
|
|
}
|
2002-10-25 20:19:56 +00:00
|
|
|
public void setParentContainer(Container c) {
|
|
|
|
}
|
2002-11-28 16:16:27 +00:00
|
|
|
public void setPlayer(QTDrawable player) {
|
|
|
|
this.player = (QTPlayer)player;
|
2002-10-25 20:19:56 +00:00
|
|
|
}
|
2002-11-28 16:16:27 +00:00
|
|
|
public QTPlayer getPlayer() {
|
2002-10-25 20:19:56 +00:00
|
|
|
return player;
|
|
|
|
}
|
2002-11-28 16:16:27 +00:00
|
|
|
public void setCanvas(QTCanvas canvas) {
|
2002-10-25 20:19:56 +00:00
|
|
|
this.canvas = canvas;
|
|
|
|
}
|
2002-11-28 16:16:27 +00:00
|
|
|
public QTCanvas getCanvas() {
|
2002-10-25 20:19:56 +00:00
|
|
|
return canvas;
|
|
|
|
}
|
2002-11-28 16:16:27 +00:00
|
|
|
|
|
|
|
|
2002-10-25 20:19:56 +00:00
|
|
|
//contract methods - initialize
|
2002-11-28 16:16:27 +00:00
|
|
|
public void displayBorders(boolean borders) throws SmartMoviePanelException {
|
2002-10-25 20:19:56 +00:00
|
|
|
}
|
2002-11-28 16:16:27 +00:00
|
|
|
public void displayController(boolean controller) throws SmartMoviePanelException {
|
2002-10-25 20:19:56 +00:00
|
|
|
}
|
2002-11-28 16:16:27 +00:00
|
|
|
|
|
|
|
public void loadMovie(URL mediaURL) throws SmartMoviePanelException {
|
2002-10-25 20:19:56 +00:00
|
|
|
//Initialize a QT session and add a test image
|
2002-11-28 16:16:27 +00:00
|
|
|
|
2002-10-25 20:19:56 +00:00
|
|
|
//These three try/catch blocks come from PlayMovie.java copyright
|
|
|
|
// Apple Co. I'm using it to test that QT and QT4Java exist
|
2002-11-28 16:16:27 +00:00
|
|
|
try {
|
2002-10-25 20:19:56 +00:00
|
|
|
if (QTSession.isInitialized() == false) {
|
|
|
|
QTSession.open();
|
2002-11-28 16:16:27 +00:00
|
|
|
try {
|
2002-10-25 20:19:56 +00:00
|
|
|
setCanvas( new QTCanvas(QTCanvas.kInitialSize, 0.5F, 0.5F) );
|
|
|
|
this.add( getCanvas() );
|
|
|
|
getCanvas().setClient(ImageDrawer.getQTLogo(), true);
|
2002-11-28 16:16:27 +00:00
|
|
|
} catch(QTException qte) {
|
2002-10-25 20:19:56 +00:00
|
|
|
qte.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2002-11-28 16:16:27 +00:00
|
|
|
} catch (NoClassDefFoundError er) {
|
2002-10-25 20:19:56 +00:00
|
|
|
add (new Label ("Can't Find QTJava classes"), "North");
|
|
|
|
add (new Label ("Check install and try again"), "South");
|
2002-11-28 16:16:27 +00:00
|
|
|
} catch (SecurityException se) {
|
2002-10-25 20:19:56 +00:00
|
|
|
// this is thrown by MRJ trying to find QTSession class
|
|
|
|
add (new Label ("Can't Find QTJava classes"), "North");
|
|
|
|
add (new Label ("Check install and try again"), "South");
|
2002-11-28 16:16:27 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
// do a dynamic test for QTException
|
2002-10-25 20:19:56 +00:00
|
|
|
//so the QTException class is not loaded unless
|
|
|
|
// an unknown exception is thrown by the runtime
|
2002-11-28 16:16:27 +00:00
|
|
|
if (e instanceof ClassNotFoundException || e instanceof java.io.FileNotFoundException) {
|
2002-10-25 20:19:56 +00:00
|
|
|
add (new Label ("Can't Find QTJava classes"), "North");
|
|
|
|
add (new Label ("Check install and try again"), "South");
|
2002-11-28 16:16:27 +00:00
|
|
|
} else if (e instanceof QTException) {
|
2002-10-25 20:19:56 +00:00
|
|
|
add (new Label ("Problem with QuickTime install"), "North");
|
|
|
|
if (((QTException)e).errorCode() == -2093)
|
2002-11-28 16:16:27 +00:00
|
|
|
add (new Label ("QuickTime must be installed"), "South");
|
2002-10-25 20:19:56 +00:00
|
|
|
else
|
|
|
|
add (new Label (e.getMessage()), "South");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-28 16:16:27 +00:00
|
|
|
try {
|
|
|
|
this.remove( getCanvas() );
|
|
|
|
setPlayer(QTFactory.makeDrawable(mediaURL.toString()));
|
2002-10-25 20:19:56 +00:00
|
|
|
getCanvas().setClient( getPlayer(), true );
|
|
|
|
this.add( getCanvas() );
|
2002-11-28 16:16:27 +00:00
|
|
|
System.out.println("loadMovie:"+mediaURL.toString());
|
2002-11-02 20:20:30 +00:00
|
|
|
|
2002-11-28 16:16:27 +00:00
|
|
|
myMoviesTimeBase = getPlayer().getTimeBase();
|
|
|
|
theJumpper = new myJumpCallBack(myMoviesTimeBase);
|
|
|
|
theJumpper.callMeWhen();
|
|
|
|
theRater = new myRateCallBack(myMoviesTimeBase, 0, StdQTConstants.triggerRateChange);
|
|
|
|
theRater.callMeWhen();
|
|
|
|
Timer timer = new Timer(10,1,new Tickler(), getPlayer().getMovieController().getMovie());
|
|
|
|
timer.setActive(true);
|
|
|
|
} catch(QTException qte) {
|
|
|
|
System.out.println("loadMovie failed");
|
2002-10-25 20:19:56 +00:00
|
|
|
qte.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2002-11-02 20:20:30 +00:00
|
|
|
|
2002-10-25 20:19:56 +00:00
|
|
|
//contract methods - control media
|
2002-11-28 16:16:27 +00:00
|
|
|
public void cmd_playOn() throws SmartMoviePanelException {
|
|
|
|
try {
|
2002-10-25 20:19:56 +00:00
|
|
|
getPlayer().setRate(1.0F);
|
2002-11-28 16:16:27 +00:00
|
|
|
} catch(QTException qte) {
|
2002-10-25 20:19:56 +00:00
|
|
|
qte.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2002-11-28 16:16:27 +00:00
|
|
|
public void cmd_playSegment(Integer startTime, Integer stopTime) throws SmartMoviePanelException {
|
|
|
|
try {
|
|
|
|
int myScale = getPlayer().getScale();
|
|
|
|
cmd_stop();
|
|
|
|
getPlayer().setTime( (startTime.intValue() * myScale) / 1000 );
|
2002-10-25 20:19:56 +00:00
|
|
|
|
2002-11-28 16:16:27 +00:00
|
|
|
if (stopTime == null) {
|
|
|
|
myMoviesTimeBase.setStopTime(new TimeRecord(myScale, getEndTime()));
|
|
|
|
//System.out.println("startTime:"+(startTime.intValue()*myScale)/1000+" stopTime: to the End" );
|
|
|
|
} else {
|
|
|
|
myMoviesTimeBase.setStopTime(new TimeRecord(myScale, (stopTime.intValue()*myScale)/1000));
|
|
|
|
//System.out.println("startTime:"+(startTime.intValue()*myScale)/1000+" stopTime:"+(stopTime.intValue()*myScale)/1000 );
|
|
|
|
}
|
2002-10-25 20:19:56 +00:00
|
|
|
cmd_playOn();
|
|
|
|
}
|
2002-11-28 16:16:27 +00:00
|
|
|
catch (SmartMoviePanelException smpe) {
|
|
|
|
}
|
|
|
|
catch (StdQTException sqte) {
|
|
|
|
}
|
|
|
|
catch (QTException qte) {
|
|
|
|
}
|
2002-10-25 20:19:56 +00:00
|
|
|
}
|
2002-11-28 16:16:27 +00:00
|
|
|
public void cmd_stop() throws SmartMoviePanelException {
|
|
|
|
try {
|
2002-10-25 20:19:56 +00:00
|
|
|
getPlayer().setRate(0.0F);
|
2002-11-28 16:16:27 +00:00
|
|
|
} catch(QTException qte) {
|
2002-10-25 20:19:56 +00:00
|
|
|
qte.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2002-11-28 16:16:27 +00:00
|
|
|
|
2002-10-25 20:19:56 +00:00
|
|
|
//contract methods - media status
|
2002-11-02 20:20:30 +00:00
|
|
|
public boolean isInitialized() {
|
|
|
|
return true; //FIXME what should this do?
|
2002-10-25 20:19:56 +00:00
|
|
|
}
|
|
|
|
public boolean isPlaying() {
|
2002-11-02 20:20:30 +00:00
|
|
|
try {
|
2002-11-28 16:16:27 +00:00
|
|
|
if (player.getRate() > 0)
|
2002-11-02 20:20:30 +00:00
|
|
|
return true;
|
|
|
|
} catch (StdQTException stdqte) {
|
|
|
|
stdqte.printStackTrace();
|
|
|
|
}
|
|
|
|
return false;
|
2002-10-25 20:19:56 +00:00
|
|
|
}
|
2002-11-28 16:16:27 +00:00
|
|
|
//doit envoyer le temps en sec fois 1000
|
|
|
|
public int getCurrentTime() {
|
2002-10-25 20:19:56 +00:00
|
|
|
try {
|
2002-11-28 16:16:27 +00:00
|
|
|
int myScale = getPlayer().getScale();
|
|
|
|
//System.out.println("getCurrentTime():"+(player.getTime()*1000)/myScale);
|
|
|
|
return (player.getTime()*1000)/myScale;
|
2002-10-25 20:19:56 +00:00
|
|
|
} catch (StdQTException stqte) {
|
|
|
|
stqte.printStackTrace();
|
2002-11-02 20:20:30 +00:00
|
|
|
return 0;
|
2002-11-28 16:16:27 +00:00
|
|
|
} catch (QTException qte) {
|
|
|
|
System.out.println("getCurrentTimeErr");
|
|
|
|
return 0;
|
2002-10-25 20:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
2002-11-28 16:16:27 +00:00
|
|
|
public int getEndTime() {
|
2002-10-25 20:19:56 +00:00
|
|
|
try {
|
2002-11-28 16:16:27 +00:00
|
|
|
int myScale = getPlayer().getScale();
|
|
|
|
return (player.getDuration()*1000)/myScale;
|
2002-10-25 20:19:56 +00:00
|
|
|
} catch (StdQTException stqte) {
|
|
|
|
stqte.printStackTrace();
|
2002-11-02 20:20:30 +00:00
|
|
|
return 0;
|
2002-11-28 16:16:27 +00:00
|
|
|
} catch (QTException qte) {
|
|
|
|
System.out.println("getCurrentTimeErr");
|
|
|
|
return 0;
|
2002-10-25 20:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-28 16:16:27 +00:00
|
|
|
public SmartQT4JPlayer() {
|
2002-10-25 20:19:56 +00:00
|
|
|
super( new GridLayout() );
|
|
|
|
}
|
|
|
|
|
|
|
|
// inner classes
|
|
|
|
|
|
|
|
|
2002-11-28 16:16:27 +00:00
|
|
|
class myRateCallBack extends quicktime.std.clocks.RateCallBack {
|
|
|
|
public myRateCallBack(TimeBase tb, int scale, int flag) throws QTException {
|
|
|
|
super(tb, scale, flag);
|
2002-10-25 20:19:56 +00:00
|
|
|
}
|
2002-11-28 16:16:27 +00:00
|
|
|
public void execute() {
|
|
|
|
try {
|
|
|
|
//System.out.println("myRateCallBack: " + String.valueOf(rateWhenCalled));
|
|
|
|
if (rateWhenCalled > 0)
|
|
|
|
launchAnnotationTimer();
|
|
|
|
else
|
|
|
|
cancelAnnotationTimer();
|
2002-10-25 20:19:56 +00:00
|
|
|
cancel();
|
|
|
|
callMeWhen();
|
2002-11-28 16:16:27 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
System.out.println("myRateCallBack err: "+e.getMessage());
|
|
|
|
}
|
2002-10-25 20:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
2002-11-28 16:16:27 +00:00
|
|
|
class myJumpCallBack extends quicktime.std.clocks.TimeJumpCallBack {
|
|
|
|
public myJumpCallBack(TimeBase tb) throws QTException {
|
|
|
|
super(tb);
|
|
|
|
}
|
|
|
|
public void execute() {
|
2002-11-02 20:20:30 +00:00
|
|
|
try {
|
2002-11-28 16:16:27 +00:00
|
|
|
//System.out.println("myJumpCallBack: " + String.valueOf(rateWhenCalled));
|
|
|
|
if (rateWhenCalled > 0)
|
|
|
|
launchAnnotationTimer();
|
|
|
|
cancel();
|
|
|
|
callMeWhen();
|
|
|
|
} catch (Exception e) {
|
|
|
|
System.out.println("myJumpCallBack err: "+e.getMessage());
|
|
|
|
}
|
2002-10-25 20:19:56 +00:00
|
|
|
}
|
2002-11-28 16:16:27 +00:00
|
|
|
}
|
|
|
|
public class Tickler implements Ticklish {
|
|
|
|
public void timeChanged(int newTime) throws QTException {
|
|
|
|
//System.out.println("*** TimerClass *** timeChanged at:"+newTime);
|
|
|
|
}
|
|
|
|
public boolean tickle(float er,int time) throws QTException {
|
|
|
|
//System.out.println("*** TimerClass *** tickle at:"+time);
|
|
|
|
return true;
|
2002-10-25 20:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
2002-11-28 16:16:27 +00:00
|
|
|
}
|