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); ...

Get QuickTime for Java: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.