TweetFollow Us on Twitter

Krakatoa, East of Java

Volume Number: 20 (2004)
Issue Number: 1
Column Tag: Programming

QuickTime Toolkit

by Tim Monroe

Krakatoa, East of Java

Developing QuickTime Applications with Java

Introduction

Java is an object-oriented programming language and set of associated class libraries developed by Sun Microsystems in the early- to mid-1990's. It was designed and written largely by James Gosling, who sought to provide a simpler, more secure version of C++. The Java designers began with a syntax based on the C programming language (to promote familiarity with the new language among existing developers) but eliminated elements that promoted unstructured code (like the goto statement) or increased the likelihood of programming error or system misuse (like pointer arithmetic). The result was a clean, simple language that allowed developers an easy migration path from the world of procedural programming into the world of object-oriented programming. Java virtual machines -- the runtime engines for compiled Java code -- have been developed for a wide array of operating systems and devices.

QuickTime for Java is a set of Java classes and methods that implement large parts of the QuickTime multimedia architecture. Introduced in 1998 at the JavaOne conference, it can be used to develop standalone applications and applets (that is, code that runs within a larger host application, such as a web browser) that harness QuickTime's multimedia capabilities. Because they require QuickTime, QuickTime for Java applications and applets can run only on Macintosh and Windows computers.

In this article and the next two articles, I want to take a look at using QuickTime for Java to develop QuickTime applications. As in the past few QuickTime Toolkit articles, I want to see how to build a multi-window movie playback and editing application. Let's call this application "JaVeez". I also want to investigate ways to extend our application to handle potentially more complicated tasks. For the moment we'll focus solely on building an application that runs on Mac OS X. After we've done that, we'll take a look at the kind of changes we need to make in order for JaVeez to run on Windows operating systems as well.

Throughout these articles, we'll be using the latest released versions of Java and QuickTime for Java. At the time of this writing, the current version of the Java runtime engine on Mac OS X is Java 2 Standard Edition (J2SE) version 1.4.1, which was released in early 2003. This version incorporates a number of changes that allow applications to conform more closely to the standard Mac OS X Aqua look-and-feel. In particular, it allows applications to receive and respond to Apple events, which is essential (for instance) in allowing applications to open files dropped onto the application icon. We'll also rely on the version of QuickTime for Java included with QuickTime 6.4, which is the first release of this product that supports J2SE 1.4.1 on Mac OS X. (The version number of this new QuickTime for Java is 6.1.) The differences between this version of QuickTime for Java and earlier versions are substantial, but here I'm more interested in seeing how things are done using the current versions of these tools than in enumerating the precise changes from earlier versions.

We'll begin this article by creating a new project based on the Java AWT application template project provided by the Xcode development environment. We'll modify that project as necessary to support opening QuickTime movie files and displaying their movies in windows on the screen. Then we'll see how to create the application's menus and menu bar, and how to handle a few of the menu items in those menus.

In the next article, we'll continue working on JaVeez. We'll add the ability to edit movies and to save edited movies into their movie files. We'll also see how to support the standard document-related behaviors (such as prompting a user to save or discard changes to an edited file when the movie window is closed).

The Project

So let's get started. Launch Xcode and select "New Project..." in the File menu. In the list of available projects, scroll down to find the Java projects and then select "Java AWT Application", as in Figure 1. Name the new project "JaVeez" and save it in any location you like.


Figure 1: The list of available Java projects

AWT (which is short for "Abstract Window Toolkit") is a set of Java classes for creating and managing an application's user interface. It allows us to create windows, dialog boxes, menus, scrollbars, text labels, and so forth, using code that is platform-independent. AWT also provides a framework for handling events on items in the application's user interface.

The main official alternative to AWT is a set of classes called Swing. Swing is built on top of AWT and in many cases provides greater functionality than pure AWT. For instance, it's not possible, using AWT, to set the window modification state (so that the close button of a window whose document has been edited is drawn with a dot inside, as in Figure 2). It's fairly easy to do this in Swing, however. Similarly, Swing provides classes to display help tags (also called tool tips) on objects in the user interface, while AWT does not.


Figure 2: A modified movie window

For this reason and others, Apple generally recommends that Mac OS X Java applications be built using Swing window components instead of AWT window components. (In Java parlance, a component is any object that can be drawn on the screen and become the target of user actions.) However, QuickTime for Java does not easily support embedding a movie inside of a Swing component, if we want to attach a movie controller to that movie. So we'll use AWT to handle our application's movie windows and menus. In the next article, though, we'll see how to work with a few Swing components.

Modifying the Project

Once we've given our new project a name and a location, the new project window opens (Figure 3).


Figure 3: The new project window

As you can see, there are three files with the filename extension ".java"; these are the source code files for this project. Let's go ahead and remove the files PrefPane.java and AboutBox.java, because our application will not support setting any preferences and because we'll develop a better way to handle our application's About box (in the next article).

Next, we need to add a file to the project. Select "Add Frameworks..." in the Project menu and navigate to the System/Library/Java/Extensions folder. Then select the file QTJava.zip. This file contains the QuickTime for Java packages that we'll need to use in our application. To make those packages available in our application, we need to import them. Add these lines near the top of the file JaVeez.java, after any existing import statements.

import quicktime.*;
import quicktime.io.*;
import quicktime.qd.*;
import quicktime.std.*;
import quicktime.std.clocks.*;
import quicktime.std.movies.*;
import quicktime.app.view.*;

The first non-import statement in this file is the beginning of the declaration of the JaVeez class:

public class JaVeez extends Frame {

This indicates that JaVeez is a subclass of (or extends) the AWT class Frame, which is the class for top-level windows with title bars and borders. Our movie windows will be instances of this class.

Immediately following the class declaration, you'll find declarations of class variables and instance variables. Here are the class variables we want JaVeez to support:

private static int nextHorizPos = 50;
private static int nextVertPos = 50;
private static Application fApplication = null;
private static ResourceBundle resBundle = null;
private static boolean launchedFromDrop = false;

There will be only one copy of each class variable, no matter how many instances of the JaVeez class our application creates (that is, no matter how many windows it opens). On the other hand, each instance of the class will get its own set of instance variables. Here are the ones we'll need to use:

private Movie m = null;
private MovieController mc = null;   
private OpenMovieFile omf = null;   
private QTComponent qtc = null;
private FileDialog fd = null;
private String baseName = null;

We'll learn what each of these variables does as we go along.

Starting Application Execution

A Java application begins execution in its main function, which is declared like this:

public static void main (String args[]) { }

In JaVeez, we'll ignore the args parameter, which contains the command-line arguments specified by the user if the application is launched on the command line. The first thing we need to do is initialize QuickTime. We'll call the open method of the QTSession class, but only if QuickTime has not already been initialized:

if (QTSession.isInitialized() == false)
   QTSession.open();

(This check is probably overkill for an application, but not for applets.) QTSession provides methods to initialize QuickTime and to provide information about the current operating environment. You must call its open method before using any other QuickTime for Java class.

If the QuickTime initialization completes successfully, we want to create a new empty movie window. We do this by calling the JaVeez constructor and passing it an empty string. Then we initialize the new frame by calling the method createNewMovieFromFile and display the frame to the user. If the user launched the application by dropping one or more movie files onto its icon, then we'll just hide that empty movie window. Listing 1 shows the main method of JaVeez. (We saw just above that launchedFromDrop is a class variable that is initialized to false; we'll see the conditions under which it's set to true in the next article.)

Listing 1: Opening the application

main
public static void main (String args[]) {
   try {
      // initialize QuickTime, but not if it's already been initialized
      if (QTSession.isInitialized() == false)
         QTSession.open();
            
      // make an empty movie window
      JaVeez jvz = new JaVeez("");
      jvz.createNewMovieFromFile(null, false);
      jvz.toFront();
       
   // hide the movie if the application was opened by a dropped movie file
      if (launchedFromDrop)
         jvz.setVisible(false);
       
   } catch (QTException err) {
      // close down QuickTime session if an exception was generated
      err.printStackTrace();
      QTSession.close();
   }
}

If an exception is thrown, we'll call the close method of the QTSession class and exit the application.

Creating a New Window

The constructor method for the JaVeez class is quite simple, as you can see in Listing 2.

Listing 2: Constructing a new frame object

JaVeez
public JaVeez (String title) {
   super(title);
   
   // get the resource bundle
   if (resBundle == null)
      resBundle = ResourceBundle.getBundle("JaVeezstrings", 
                                       Locale.getDefault());
   
   createActions();
   addMenus();
   createApplicationObject();
 
   // turn off resizing
   setResizable(false);
}

First, the constructor loads a resource bundle named "JaVeezstrings"; in JaVeez, this bundle contains a list of strings that specify menu titles, menu item titles, and the like. By loading strings from a resource bundle, we avoid having to hard-code them in our source code and thus facilitate localizing the application. For instance, when we build our menus, we retrieve the label for the New menu item in the File menu like this:

resBundle.getString("newItem")

You can look into the file JaVeezstrings to see what strings are defined therein.

After loading the resource bundle, we call three methods defined by JaVeez to set up the application's menus and menu-handling logic. Then we set the window so that it cannot be resized by the user. For simplicity, a movie window created by our application JaVeez will be set to a size that exactly contains the movie and the movie controller bar (if it's visible).

Initializing a New Movie

Most of the work required to display a QuickTime movie in an AWT frame is handled by our createNewMovieFromFile method, which is usually called immediately after the JaVeez constructor (as in Listing 1 above). We pass createNewMovieFromFile the full pathname of the file to open, or an empty string if we want the window to contain a new, empty movie. To elicit a pathname from the user, we can use the standardGetFilePreview method of the QTFile class, as follows:

QTFile qtf = QTFile.standardGetFilePreview
                                    (QTFile.kStandardQTFileTypes);
JaVeez jvz = new JaVeez(qtf.getPath());
jvz.createNewMovieFromFile(qtf.getPath(), false);

The first line of code displays the standard file-opening dialog box, shown in Figure 4:


Figure 4: The file-opening dialog box

Passing kStandardQTFileTypes to standardGetFilePreview indicates that we want the user to be able to select any type of file that QuickTime can open.

The createNewMovieFromFile method opens the specified file for reading and writing by creating a QTFile object and then passing that object to the asWrite class method of the OpenMovieFile class:

QTFile qtf = new QTFile(theFullPath);
omf = OpenMovieFile.asWrite(qtf);

If these methods succeed, createNewMovieFromFile calls the Movie constructor to create a movie object from that movie file and the MovieController constructor to create a movie controller object associated with that movie object. The Movie and MovieController classes are wrappers for QuickTime movies and movie controllers. Once we've opened a movie in a new window, most of our subsequent operations on the movie will be accomplished using methods supplied by the MovieController class.

But we still need to embed the QuickTime movie into the AWT frame. QuickTime for Java defines the class QTComponent, which represents displayable QuickTime objects. We create an instance of that class by calling the makeQTComponent factory method, and we then add that instance to the AWT frame by executing the frame's add method:

qtc = QTFactory.makeQTComponent(mc);
add(qtc.asComponent());

Our instance variable qtc is of type QTComponent, but add requires a parameter of type Component. As you can see, we call the asComponent method to get an AWT representation of the QTComponent. (If you are using Swing, you should create a QTJComponent; however, as mentioned earlier, there is no QTJComponent constructor that accepts a movie controller. That's the main reason we are using AWT components for our basic movie windows.)

The createNewMovieFromFile method then enables editing and keyboard control of the movie, using methods in the MovieController class. It finishes up by moving the movie window to the next staggered position on the screen. Listing 3 shows our complete definition of createNewMovieFromFile.

Listing 3: Opening a movie file

createNewMovieFromFile
public void createNewMovieFromFile 
            (String theFullPath, boolean useExistingWindow) {
   
   // set the window title
   baseName = basename(theFullPath);
   setTitle(baseName);
   
   try {
      if (theFullPath != null) {
         QTFile qtf = new QTFile(theFullPath);
                
         omf = OpenMovieFile.asWrite(qtf);
         m = Movie.fromFile(omf);
      } else {
         m = new Movie();
      }
            
      // create the movie controller
      mc = new MovieController(m);
            
      // create and add a QTComponent if we haven't done so yet;
      // otherwise set the movie controller
      if (qtc == null) {
         qtc = QTFactory.makeQTComponent(mc);
         add(qtc.asComponent());
      } else {
         qtc.setMovieController(mc);
      }
            
      // enable editing (unless movie is interactive) and key handling
      if ((mc.getControllerInfo() &
                   StdQTConstants.mcInfoMovieIsInteractive) == 0)
         mc.enableEditing(true);
            
      mc.setKeysEnabled(true);

       // set the initial state of the menus
      adjustMenuItems();

      if (!useExistingWindow) {
         // set initial location of the movie window
         setLocation(nextHorizPos, nextVertPos);
         nextHorizPos += 20;
         nextVertPos += 20;
      }
       
      // set the size of the enclosing frame to the size of the incoming movie
      pack();
      setVisible(true);
       
   } catch (QTException err) {
      err.printStackTrace();
   }
}

You might be wondering why be didn't just add all this code to the constructor of the JaVeez class. The main reason for breaking it out into a separate method is that that allows us to reinitialize an existing movie window from a different movie file. We'll need to do this when we handle the "Save As..." menu item in the next article.

Setting the Title of a Window

Listing 3 calls the basename method to get the base name of a movie file (that is, the portion of the full pathname that follows the rightmost path separator). It uses that name to set the window title. The basename method is defined in Listing 4.

Listing 4: Getting the base name of a pathname

basename
public String basename (String pathName) {
   if ((pathName == null) || (pathName.length() == 0))
      return(resBundle.getString("newMovieName"));
   
   // if we are passed a full pathname, trim it to the last segment
   File file = new File(pathName);

   return(file.getName());
}

We return the default name for an empty movie file (which we read from the application's resource bundle) if the string passed into the method is null or an empty string. Otherwise, we call the getName method of a File object to get the name of the specified file. As you saw in Listing 3, we store the movie's returned base name in an instance variable so that we can use it in the method that displays the standard "Save Changes" dialog box, as we'll see in the next article.

Setting the Size of a Window

The pack method called in the createNewMovieFromFile method sets the size of the content area of the frame object to the size of the movie that was just opened, including the rectangle occupied by the movie controller bar (if visible). Occasionally, we'll need to adjust the size of the movie window, even though we don't allow the user to resize it manually. For instance, when the user cuts a segment from a movie, the size of the movie may change. In that case, we'll call our own method sizeWindowToMovie (Listing 5) to resize the movie window.

Listing 5: Setting the size of a movie window

sizeWindowToMovie
public void sizeWindowToMovie () {
   try {
      QDRect rect = m.getBox();
       
      if (mc.getVisible())
         rect = mc.getBounds();
       
       // make sure that the movie has a non-zero width;
         // a zero height is okay (for example, with a music movie with no controller bar)
      if (rect.getWidth() == 0) {
         rect.setWidth(this.getSize().width);
      }
       
       // resize the frame to the calculated size, plus window borders
      setSize(rect.getWidth() + 
                        (getInsets().left + getInsets().right),
                  rect.getHeight() + 
                        (getInsets().top + getInsets().bottom));
   } catch (QTException err) {
      err.printStackTrace();
   }
}

As you can see, we just use the MovieController method getBounds to get the size of the movie and controller bar; then we add in the heights and widths of the window borders.

Menus

Creating menus and handling user selection of menu items in Java applications is reasonably straightforward. Both AWT and Swing provide classes from which we can instantiate menu bars, menus, and menu items. The only "gotcha", at least for those of us who cut our programming eyeteeth on the Macintosh, is that Java menu bars are attached to individual frames -- that is, to individual windows. That means that if no movie window is open, then JaVeez' menu bar won't contain any menus other than the Application menu, which is provided automatically by the operating system. Figure 5 shows this minimal menu bar.


Figure 5: The JaVeez menu bar when no movie windows are open

This is not an ideal situation. For one thing, it means that if the user closes all the open movie windows, the File menu disappears and there is no way to open additional movies via the menu bar. (A clever user could of course drag a movie file onto the application's icon in the Finder or in the dock.) Still, it's not a situation worth worrying too much about, since there is an easy workaround: when the application is launched, just open an empty window and move it to an offscreen location where it will not be visible. (Implementing this simple workaround is left as an exercise for the reader.)

As I said, both AWT and Swing will allow us to create menu bars, menus, and menu items. Since we're already using an AWT frame for the movie window, let's continue down that path and use the AWT menu classes. Swing does not offer any additional menu-related capabilities that we need to use in JaVeez.

Creating Actions

When the user selects an item in a menu, the Java runtime engine sends an action event (which is an object of type ActionEvent) to the menu item. The menu item in turn passes the event to any registered listeners. These listeners are actions (of type Action). So the first thing we need to do is create an action for each menu item in our application.

To create an action object, we define a concrete subclass of the AbstractAction class. This subclass must implement the actionPerformed method. Listing 6 gives our definition of the NewActionClass class, which will be instantiated to handle the New menu item.

Listing 6: Handling the New menu item

NewActionClass
public class NewActionClass extends AbstractAction {
   public NewActionClass (String text, KeyStroke shortcut) {
      super(text);
      putValue(ACCELERATOR_KEY, shortcut);
   }
   public void actionPerformed (ActionEvent e) {
      JaVeez jvz = new JaVeez("");
      jvz.createNewMovieFromFile(null, false);
      jvz.toFront();
   }
}

Similarly, Listing 7 gives our definition of the OpenActionClass class, which will be instantiated to handle the Open... menu item.

Listing 7: Handling the Open menu item

OpenActionClass
public class OpenActionClass extends AbstractAction {
   public OpenActionClass (String text, KeyStroke shortcut) {
      super(text);
      putValue(ACCELERATOR_KEY, shortcut);
   }
   public void actionPerformed (ActionEvent e) {
      try {
         QTFile qtf = QTFile.standardGetFilePreview
                                    (QTFile.kStandardQTFileTypes);
      
         JaVeez jvz = new JaVeez(qtf.getPath());
         jvz.createNewMovieFromFile(qtf.getPath(), false);
         jvz.toFront();
      } catch (QTException err) {
         if (err.errorCode() != Errors.userCanceledErr)
            err.printStackTrace();
      }
   }
}

Both of these class implementations call the method putValue to associate the action with a keystroke combination, which (as we'll see shortly) is passed to the class constructor. JaVeez declares AbstractAction subclasses for each of its dozen or so menu items. In the interest of saving space, I've omitted the remaining definitions.

Once we've defined a concrete subclass of AbstractAction for each menu item, we need to create actions for each such subclass. JaVeez declares instance variables for all of these actions:

protected Action newAction, openAction, closeAction, 
         saveAction, saveAsAction;
protected Action undoAction, cutAction, copyAction, 
         pasteAction, clearAction, selectAllAction, 
         selectNoneAction;
protected Action toggleBarAction, toggleSpeakerAction;

We create actions by invoking the class constructors. Listing 8 shows how we do this for three of these actions. Once again, the code for the remaining cases has been omitted in the interest of brevity.

Listing 8: Creating actions

createActions
public void createActions () {
   int shortcutKeyMask = 
         Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();

   // create actions that can be used by menus, buttons, toolbars, etc.
   newAction = new NewActionClass(
                     resBundle.getString("newItem"),
                        KeyStroke.getKeyStroke(KeyEvent.VK_N, 
                                                         shortcutKeyMask));
   openAction = new OpenActionClass(
                     resBundle.getString("openItem"),
                     KeyStroke.getKeyStroke(KeyEvent.VK_O, 
                                                         shortcutKeyMask));

   // lots of lines omitted here...

   toggleBarAction = new ToggleControllerActionClass(
                     resBundle.getString("hideControllerItem"),
                         KeyStroke.getKeyStroke(KeyEvent.VK_1, 
                                                         shortcutKeyMask));

Creating Menus and Menu Items

Now that we've created the actions that will handle selections of menu items, we can proceed to create the menu items and insert them into menus. First, let's create the main menu bar, like this:

protected MenuBar mainMenuBar = new MenuBar();

A menu bar contains menus, which are objects of type Menu. JaVeez has three application-specific menus: the File menu, the Edit menu, and the Movie menu. We'll use these instance variables to refer to them:

protected Menu fileMenu;
protected Menu editMenu;
protected Menu movieMenu;

Listing 9 shows our definition of the addMenu method, which creates these menus and their items and then adds them to the menu bar. It also sets mainMenuBar as the menu bar for the frame under construction.

Listing 9: Configuring the menu bar

addMenus
public void addMenus () {
   editMenu = new Menu(resBundle.getString("editMenu"));
   fileMenu = new Menu(resBundle.getString("fileMenu"));
   movieMenu = new Menu(resBundle.getString("movieMenu"));
   
   addFileMenuItems();
   addEditMenuItems();
   addMovieMenuItems();
   
   setMenuBar(mainMenuBar);
}

All that remains is for us to write the addFileMenuItems, addEditMenuItems, and addMovieMenuItems methods. These methods create the individual menu items, set their keyboard shortcuts, add them to the appropriate menu, and then attach the action listeners created earlier. Listing 10 shows the complete definition of the addFileMenuItems method, which uses these instance variables:

protected MenuItem miNew;
protected MenuItem miOpen;
protected MenuItem miClose;
protected MenuItem miSave;
protected MenuItem miSaveAs;

Listing 10: Adding menu items to the File menu

addFileMenuItems
public void addFileMenuItems () {
   miNew = new MenuItem(resBundle.getString("newItem"));
   miNew.setShortcut(new MenuShortcut(KeyEvent.VK_N, 
                                                            false));
   fileMenu.add(miNew).setEnabled(true);
   miNew.addActionListener(newAction);
      
   miOpen = new MenuItem(resBundle.getString("openItem"));
   miOpen.setShortcut(new MenuShortcut(KeyEvent.VK_O, 
                                                            false));
   fileMenu.add(miOpen).setEnabled(true);
   miOpen.addActionListener(openAction);
      
   miClose = new MenuItem(resBundle.getString("closeItem"));
   miClose.setShortcut(new MenuShortcut(KeyEvent.VK_W, 
                                                            false));
   fileMenu.add(miClose).setEnabled(true);
   miClose.addActionListener(closeAction);
      
   fileMenu.addSeparator();

   miSave = new MenuItem(resBundle.getString("saveItem"));
   miSave.setShortcut(new MenuShortcut(KeyEvent.VK_S, 
                                                            false));
   fileMenu.add(miSave).setEnabled(false);
   miSave.addActionListener(saveAction);
      
   miSaveAs = new MenuItem
                        (resBundle.getString("saveasItem"));
   miSaveAs.setShortcut(new MenuShortcut(KeyEvent.VK_S,
                                                             true));
   fileMenu.add(miSaveAs).setEnabled(true);
   miSaveAs.addActionListener(saveAsAction);
   
   mainMenuBar.add(fileMenu);
}

Notice that we call the addSeparator method to insert a menu separator into the menu. Figure 6 shows the resulting File menu.


Figure 6: The File menu of JaVeez

Movie Playback

So, we've managed to open a movie file in a window, appropriately sized to exactly contain the movie at its natural size and the associated movie controller bar (if it's visible). Figure 7 shows a movie window displayed by JaVeez. As you can see, there is no grow button in the movie controller bar and the zoom button in the title bar is disabled; both of these result from our decision to disallow manual movie window resizing.


Figure 7: A JaVeez movie window

AWT handles all the low-level nitty-gritty of displaying and managing the open movie windows. It handles dragging windows around, as well as iconifying (that is, minimizing) and deiconifying them. And the MovieController object handles most events that occur within the window frame. It handles mouse clicks within the movie and, for QuickTime VR movies, zooming in and out using the Shift and Control keys.

Nonetheless, the movie controller is neglecting to handle some events that, in theory, it ought to be handling. It does not start or stop a linear movie when the spacebar is pressed, and it does not pan or tilt a QuickTime VR movie when the arrow keys are pressed. This is a bug in QuickTime for Java 6.1, which will be fixed in a future release. In the meantime, it's easy enough to work around this misbehavior. In this section, we'll see how to do that, and also how to handle the "Hide Controller Bar" menu item in the Movie menu.

Handling Keys

To get the movie controller to process key events, we can have the JaVeez class implement the key listener interface. To do this, we'll change the declaration of JaVeez slightly, so that it looks like this:

public class JaVeez extends Frame implements KeyListener {}

Then we need to provide implementations of each of the methods defined in that interface. There are three such methods: keyPressed, keyReleased, and keyTyped. The keyPressed method is invoked when a key is pressed; the keyReleased method is invoked when a key is released; the keyTyped method is invoked when a key is pressed and then released. For our purposes, we want to implement the keyPressed method, shown in Listing 11. (The remaining two methods are empty.)

Listing 11: Handling key-pressed events

keyPressed
public void keyPressed (KeyEvent e) {
   try {
      mc.key(e.getKeyCode(), e.getModifiers());
   } catch (QTException err) {
      err.printStackTrace();
   }
}

We simply pass the key code and the key modifiers to the key method of the MovieController. Problem solved.

Handling the Movie Menu

It's also quite easy to hide or show the movie controller bar. When the user selects the "Hide Controller Bar" menu item, JaVeez executes the method defined in Listing 12.

Listing 12: Toggling the visibility state of the controller bar

actionPerformed
public void actionPerformed (ActionEvent e) {
   try {
      mc.setVisible(!mc.getVisible());
      sizeWindowToMovie();
      adjustMenuItems();
   } catch (QTException err) {
      err.printStackTrace();
   }
}

We'll take a look at the adjustMenuItems method in the next article. In part, it changes the menu item text to reflect the current state of the controller bar visibility.

Conclusion

In this article, we've seen how to develop a basic Java application that can open one or more QuickTime movie files and display their movies in windows on the screen. We'll continue developing JaVeez -- by adding the ability to edit movies and then save those edited movies into their files -- in the next article.

Acknowledgements

Thanks are due to Anant Sonone and Tom Maremaa for reviewing this article and providing some helpful comments. Special thanks are also due to Chris Adamson (of Subsequently and Furthermore, Inc.) and Daniel H. Steinberg (of Dim Sum Thinking, Inc.) for their assistance and support.


Tim Monroe is a member of the QuickTime engineering team. You can contact him at monroe@mactech.com. The views expressed here are not necessarily shared by his employer.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Jump into one of Volkswagen's most...
We spoke about PUBG Mobile yesterday and their Esports development, so it is a little early to revisit them, but we have to because this is just too amusing. Someone needs to tell Krafton that PUBG Mobile is a massive title because out of all the... | Read more »
PUBG Mobile will be releasing more ways...
The emergence of Esports is perhaps one of the best things to happen in gaming. It shows our little hobby can be a serious thing, gets more people intrigued, and allows players to use their skills to earn money. And on that last point, PUBG Mobile... | Read more »
Genshin Impact 5.1 launches October 9th...
If you played version 5.0 of Genshin Impact, you would probably be a bit bummed by the lack of a Pyro version of the Traveller. Well, annoyingly HoYo has stopped short of officially announcing them in 5.1 outside a possible sighting in livestream... | Read more »
A Phoenix from the Ashes – The TouchArca...
Hello! We are still in a transitional phase of moving the podcast entirely to our Patreon, but in the meantime the only way we can get the show’s feed pushed out to where it needs to go is to post it to the website. However, the wheels are in motion... | Read more »
Race with the power of the gods as KartR...
I have mentioned it before, somewhere in the aether, but I love mythology. Primarily Norse, but I will take whatever you have. Recently KartRider Rush+ took on the Arthurian legends, a great piece of British mythology, and now they have moved on... | Read more »
Tackle some terrifying bosses in a new g...
Blue Archive has recently released its latest update, packed with quite an arsenal of content. Named Rowdy and Cheery, you will take part in an all-new game mode, recruit two new students, and follow the team's adventures in Hyakkiyako. [Read... | Read more »
Embrace a peaceful life in Middle-Earth...
The Lord of the Rings series shows us what happens to enterprising Hobbits such as Frodo, Bilbo, Sam, Merry and Pippin if they don’t stay in their lane and decide to leave the Shire. It looks bloody dangerous, which is why September 23rd is an... | Read more »
Athena Crisis launches on all platforms...
Athena Crisis is a game I have been following during its development, and not just because of its brilliant marketing genius of letting you play a level on the webpage. Well for me, and I assume many of you, the wait is over as Athena Crisis has... | Read more »
Victrix Pro BFG Tekken 8 Rage Art Editio...
For our last full controller review on TouchArcade, I’ve been using the Victrix Pro BFG Tekken 8 Rage Art Edition for PC and PlayStation across my Steam Deck, PS5, and PS4 Pro for over a month now. | Read more »
Matchday Champions celebrates early acce...
Since colossally shooting themselves in the foot with a bazooka and fumbling their deal with EA Sports, FIFA is no doubt scrambling for other games to plaster its name on to cover the financial blackhole they made themselves. Enter Matchday, with... | Read more »

Price Scanner via MacPrices.net

Apple Watch Ultra available today at Apple fo...
Apple has several Certified Refurbished Apple Watch Ultra models available in their online store for $589, or $210 off original MSRP. Each Watch includes Apple’s standard one-year warranty, a new... Read more
Amazon is offering coupons worth up to $109 o...
Amazon is offering clippable coupons worth up to $109 off MSRP on certain Silver and Blue M3-powered 24″ iMacs, each including free shipping. With the coupons, these iMacs are $150-$200 off Apple’s... Read more
Amazon is offering coupons to take up to $50...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for up to $110 off MSRP, each including free delivery. Prices are valid after free coupons available on each mini’s product page, detailed... Read more
Use your Education discount to take up to $10...
Need a new Apple iPad? If you’re a student, teacher, or staff member at any educational institution, you can use your .edu email address when ordering at Apple Education to take up to $100 off the... Read more
Apple has 15-inch M2 MacBook Airs available f...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs available starting at $1019 and ranging up to $300 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at Apple.... Read more
Mac Studio with M2 Max CPU on sale for $1749,...
B&H Photo has the standard-configuration Mac Studio model with Apple’s M2 Max CPU in stock today and on sale for $250 off MSRP, now $1749 (12-Core CPU and 32GB RAM/512GB SSD). B&H offers... Read more
Save up to $260 on a 15-inch M3 MacBook Pro w...
Apple has Certified Refurbished 15″ M3 MacBook Airs in stock today starting at only $1099 and ranging up to $260 off MSRP. These are the cheapest M3-powered 15″ MacBook Airs for sale today at Apple.... Read more
Apple has 16-inch M3 Pro MacBook Pro in stock...
Apple has a full line of 16″ M3 Pro MacBook Pros available, Certified Refurbished, starting at $2119 and ranging up to $440 off MSRP. Each model features a new outer case, shipping is free, and an... Read more
Apple M2 Mac minis on sale for $120-$200 off...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for $110-$200 off MSRP this weekend, each including free delivery: – Mac mini M2/256GB SSD: $469, save $130 – Mac mini M2/512GB SSD: $689.... Read more
Clearance 9th-generation iPads are in stock t...
Best Buy has Apple’s 9th generation 10.2″ WiFi iPads on clearance sale for starting at only $199 on their online store for a limited time. Sale prices for online orders only, in-store prices may vary... Read more

Jobs Board

Senior Mobile Engineer-Android/ *Apple* - Ge...
…Trust/Other Required:** NACI (T1) **Job Family:** Systems Engineering **Skills:** Apple Devices,Device Management,Mobile Device Management (MDM) **Experience:** 10 + Read more
Sonographer - *Apple* Hill Imaging Center -...
Sonographer - Apple Hill Imaging Center - Evenings Location: York Hospital, York, PA Schedule: Full Time Full Time (80 hrs/pay period) Evenings General Summary Read more
*Apple* Systems Administrator - JAMF - Activ...
…**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.