O'Reilly logo

QuickTime for Java: A Developer's Notebook by Chris Adamson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2. Playing Movies

Even if you have more elaborate plans for QuickTime for Java, I’m going to assume that your plans will, at some point in time, require reading in a movie or other QuickTime-compatible file, locally or from the network. This chapter presents basic techniques of getting a Movie object, getting it into the Java display space, and adding more sophisticated controls so that your user (or just your code) can know what’s happening inside a playing movie and take control.

Building a Simple Movie Player

I’ll begin with “the simplest thing that could possibly work:” an application to ask the user for the location of a QuickTime file, which is then opened and put in a Java AWT Frame.

How do I do that?

Example 2-1 shows the code for a simple movie player.

Example 2-1. Simple movie player

package com.oreilly.qtjnotebook.ch02; import quicktime.*; import quicktime.app.view.*; import quicktime.std.movies.*; import quicktime.io.*; import com.oreilly.qtjnotebook.ch01.QTSessionCheck; import java.awt.*; 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); } 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); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required