Commit 86a94e42 authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.

Initial commit

parents
9780596008222
\ No newline at end of file
## Example files for the title:
# QuickTime for Java: A Developer's Notebook, by Chris Adamson
[![QuickTime for Java: A Developer's Notebook, by Chris Adamson](http://akamaicovers.oreilly.com/images/9780596008222/cat.gif)](https://www.safaribooksonline.com/library/view/title/0596008228//)
The following applies to example files from material published by O’Reilly Media, Inc. Content from other publishers may include different rules of usage. Please refer to any additional usage rights explained in the actual example files or refer to the publisher’s website.
O'Reilly books are here to help you get your job done. In general, you may use the code in O'Reilly books in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from our books does not require permission. Answering a question by citing our books and quoting example code does not require permission. On the other hand, selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Incorporating a significant amount of example code from our books into your product's documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN.
If you think your use of code examples falls outside fair use or the permission given here, feel free to contact us at <permissions@oreilly.com>.
Please note that the examples are not production code and have not been carefully testing. They are provided "as-is" and come with no warranty of any kind.
This diff is collapsed.
#jvm.path=c:\\Progra~1\\Java\\j2re1.4.2\\bin\\java
qtjavazip.file=c:\\Progra~1\\Java\\j2re1.4.2\\lib\\ext\\QTJava.zip
/*
Copyright (c) 2004, Chris Adamson
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.oreilly.qtjnotebook.ch01;
import quicktime.*;
public class QTSessionCheck {
private Thread shutdownHook;
private static QTSessionCheck instance;
private QTSessionCheck() throws QTException {
super();
// init
QTSession.open();
// create shutdown handler
shutdownHook = new Thread() {
public void run() {
// QTSession.close();
QTSession.exitMovies();
}
};
Runtime.getRuntime().addShutdownHook(shutdownHook);
}
private static QTSessionCheck getInstance() throws QTException {
if (instance == null)
instance = new QTSessionCheck();
return instance;
}
public static void check() throws QTException {
// gets instance. if a new one needs to be created,
// it calls QTSession.open() and creates a shutdown hook
// to call QTSession.close()
getInstance();
}
public static void main (String[] args) {
try {
QTSessionCheck.check();
System.exit(0);
} catch (QTException qte) {
qte.printStackTrace();
}
}
}
/*
Copyright (c) 2004, Chris Adamson
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.oreilly.qtjnotebook.ch01;
import quicktime.QTSession;
import quicktime.util.QTBuild;
public class QTVersionCheck {
public static void main (String[] args) {
try {
QTSession.open();
System.out.println ("QT version: " +
QTSession.getMajorVersion() +
"." +
QTSession.getMinorVersion());
System.out.println ("QTJ version: " +
QTBuild.getVersion() +
"." +
QTBuild.getSubVersion());
QTSession.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
/*
Copyright (c) 2004, Chris Adamson
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.oreilly.qtjnotebook.ch01;
import quicktime.*;
import quicktime.app.time.*;
import quicktime.io.*;
import quicktime.std.*;
import quicktime.std.movies.*;
import java.io.*;
public class TrivialAudioPlayer {
public static void main (String[] args) {
if (args.length != 1) {
System.out.println (
"Usage: TrivialAudioPlayer <file>");
return;
}
try {
QTSessionCheck.check();
QTFile f = new QTFile (new File(args[0]));
OpenMovieFile omf = OpenMovieFile.asRead(f);
Movie movie = Movie.fromFile (omf);
TaskAllMovies.addMovieAndStart();
movie.start();
} catch (QTException e) {
e.printStackTrace();
}
}
}
/*
Copyright (c) 2004, Chris Adamson
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.oreilly.qtjnotebook.ch02;
import quicktime.*;
import quicktime.std.*;
import quicktime.app.view.*;
import quicktime.std.movies.*;
import quicktime.std.movies.media.*;
import quicktime.io.*;
import java.awt.*;
import javax.swing.JOptionPane;
import com.oreilly.qtjnotebook.ch01.QTSessionCheck;
public class BasicDataRefQTPlayer extends Frame {
public BasicDataRefQTPlayer (Movie m) throws QTException {
super ("Basic QT Player");
m.prePreroll(0, 1.0f);
m.preroll(0, 1.0f);
QTComponent qc = QTFactory.makeQTComponent (m);
Component c = qc.asComponent();
add (c);
pack();
}
public static void main (String[] args) {
try {
QTSessionCheck.check();
String url =
JOptionPane.showInputDialog (null,
"Enter URL:");
DataRef dr = new DataRef (url);
Movie m = Movie.fromDataRef (dr,
StdQTConstants.newMovieActive);
System.out.println ("got movie");
Frame f = new BasicDataRefQTPlayer (m);
f.pack();
f.setVisible(true);
m.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
/*
Copyright (c) 2004, Chris Adamson
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.oreilly.qtjnotebook.ch02;
import quicktime.*;
import quicktime.app.view.*;
import quicktime.std.movies.*;
import quicktime.io.*;
import java.awt.*;
import java.awt.event.*;
import com.oreilly.qtjnotebook.ch01.QTSessionCheck;
public class BasicQTButtons extends Frame
implements ActionListener {
Button revButton,
stopButton,
startButton,
fwdButton;
Movie theMovie;
public BasicQTButtons (Movie m) throws QTException {
super ("Basic QT Player");
theMovie = m;
QTComponent qc = QTFactory.makeQTComponent (m);
Component c = qc.asComponent();
setLayout (new BorderLayout());
add (c, BorderLayout.CENTER);
Panel buttons = new Panel();
revButton = new Button("<");
revButton.addActionListener (this);
stopButton = new Button ("0");
stopButton.addActionListener (this);
startButton = new Button ("1");
startButton.addActionListener (this);
fwdButton = new Button (">");
fwdButton.addActionListener (this);
buttons.add (revButton);
buttons.add (stopButton);
buttons.add (startButton);
buttons.add (fwdButton);
add (buttons, BorderLayout.SOUTH);
pack();
}
public void actionPerformed (ActionEvent e) {
try {
if (e.getSource() == revButton)
theMovie.setRate (theMovie.getRate() - 0.5f);
else if (e.getSource() == stopButton)
theMovie.stop();
else if (e.getSource() == startButton)
theMovie.start();
else if (e.getSource() == fwdButton)
theMovie.setRate (theMovie.getRate() + 0.5f);
} catch (QTException qte) {
qte.printStackTrace();
}
}
public static void main (String[] args) {
try {
QTSessionCheck.check();
QTFile file =
QTFile.standardGetFilePreview (QTFile.kStandardQTFileTypes);
OpenMovieFile omFile = OpenMovieFile.asRead (file);
Movie m = Movie.fromFile (omFile);
Frame f = new BasicQTButtons (m);
f.pack();
f.setVisible(true);
m.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
/*
Copyright (c) 2004, Chris Adamson
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.oreilly.qtjnotebook.ch02;
import quicktime.*;
import quicktime.app.view.*;
import quicktime.std.*;
import quicktime.std.movies.*;
import quicktime.io.*;
import quicktime.std.clocks.*;
import java.awt.*;
import java.awt.event.*;
import com.oreilly.qtjnotebook.ch01.QTSessionCheck;
public class BasicQTCallbacks extends Frame
implements ActionListener {
Button revButton,
stopButton,
startButton,
fwdButton;
MyQTCallback myCallback;
Movie theMovie;
public BasicQTCallbacks (Movie m) throws QTException {
super ("Basic QT Player");
theMovie = m;
myCallback = new MyQTCallback (m);
QTComponent qc = QTFactory.makeQTComponent (m);
Component c = qc.asComponent();
setLayout (new BorderLayout());
add (c, BorderLayout.CENTER);
Panel buttons = new Panel();
revButton = new Button("<");
revButton.addActionListener (this);
stopButton = new Button ("0");
stopButton.addActionListener (this);
startButton = new Button ("1");
startButton.addActionListener (this);
fwdButton = new Button (">");
fwdButton.addActionListener (this);
buttons.add (revButton);
buttons.add (stopButton);
buttons.add (startButton);
buttons.add (fwdButton);
add (buttons, BorderLayout.SOUTH);
pack();
}
public void actionPerformed (ActionEvent e) {
try {
if (e.getSource() == revButton)
theMovie.setRate (theMovie.getRate() - 0.5f);
else if (e.getSource() == stopButton)
theMovie.stop();
else if (e.getSource() == startButton)
theMovie.start();
else if (e.getSource() == fwdButton)
theMovie.setRate (theMovie.getRate() + 0.5f);
} catch (QTException qte) {
qte.printStackTrace();
}
}
public static void main (String[] args) {
try {
QTSessionCheck.check();
QTFile file =
QTFile.standardGetFilePreview (QTFile.kStandardQTFileTypes);
OpenMovieFile omFile = OpenMovieFile.asRead (file);
Movie m = Movie.fromFile (omFile);
Frame f = new BasicQTCallbacks (m);
f.pack();
f.setVisible(true);
m.start();
} catch (Exception e) {
e.printStackTrace();
}
}
class MyQTCallback extends RateCallBack {
public MyQTCallback (Movie m) throws QTException {
super (m.getTimeBase(),
0,
StdQTConstants.triggerRateChange);
callMeWhen();
}
public void execute() {
if (rateWhenCalled == 0.0) {
startButton.setEnabled (true);
stopButton.setEnabled (false);
} else if (rateWhenCalled == 1.0) {
startButton.setEnabled (false);
stopButton.setEnabled (true);
}
// indicate that we want to be called again
try {
callMeWhen();
} catch (QTException qte) {
qte.printStackTrace();
}
}
}
}
/*
Copyright (c) 2004, Chris Adamson
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.oreilly.qtjnotebook.ch02;
import quicktime.*;
import quicktime.app.view.*;
import quicktime.std.movies.*;
import quicktime.io.*;
import java.awt.*;
import com.oreilly.qtjnotebook.ch01.QTSessionCheck;
public class BasicQTController extends Frame {
public BasicQTController (Movie m) throws QTException {
super ("Basic QT Controller");
MovieController mc = new MovieController(m);
QTComponent qc = QTFactory.makeQTComponent (mc);
Component c = qc.asComponent();
add (c);
pack();
}
public static void main (String[] args) {
try {
QTSessionCheck.check();
QTFile file =
QTFile.standardGetFilePreview (QTFile.kStandardQTFileTypes);
OpenMovieFile omFile = OpenMovieFile.asRead (file);
Movie m = Movie.fromFile (omFile);
Frame f = new BasicQTController (m);
f.pack();
f.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
}
/*
Copyright (c) 2004, Chris Adamson
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.oreilly.qtjnotebook.ch02;
import quicktime.*;
import quicktime.app.view.*;
import quicktime.std.movies.*;
import quicktime.io.*;
import java.awt.*;
import com.oreilly.qtjnotebook.ch01.QTSessionCheck;
public class BasicQTPlayer extends Frame {
public BasicQTPlayer (Movie m) throws QTException {
super ("Basic QT Player");
QTComponent qc = QTFactory.makeQTComponent (m);
Component c = qc.asComponent();
add (c);
pack();
}
public static void main (String[] args) {
try {
QTSessionCheck.check();
QTFile file =
QTFile.standardGetFilePreview (QTFile.kStandardQTFileTypes);
OpenMovieFile omFile = OpenMovieFile.asRead (file);
Movie m = Movie.fromFile (omFile);
Frame f = new BasicQTPlayer (m);
f.pack();
f.setVisible(true);
m.start();
} catch (Exception e) {
e.printStackTrace();
}
}
}
/*
Copyright (c) 2004, Chris Adamson
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.oreilly.qtjnotebook.ch02;
import quicktime.*;
import quicktime.app.view.*;
import quicktime.std.*;
import quicktime.std.clocks.*;
import quicktime.std.movies.*;
// import quicktime.std.movies.media.*;
import quicktime.io.*;
import java.awt.*;
import java.awt.event.*;
import com.oreilly.qtjnotebook.ch01.QTSessionCheck;
public class BasicQTStepper extends Frame
implements ActionListener {
Button revButton,
stopButton,
startButton,
fwdButton;
Movie theMovie;