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

The secrets of Penacony might soon come...
Version 2.2 of Honkai: Star Rail is on the horizon and brings the culmination of the Penacony adventure after quite the escalation in the latest story quests. To help you through this new expansion is the introduction of two powerful new... | Read more »
The Legend of Heroes: Trails of Cold Ste...
I adore game series that have connecting lore and stories, which of course means the Legend of Heroes is very dear to me, Trails lore has been building for two decades. Excitedly, the next stage is upon us as Userjoy has announced the upcoming... | Read more »
Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »

Price Scanner via MacPrices.net

Apple AirPods Pro with USB-C return to all-ti...
Amazon has Apple’s AirPods Pro with USB-C in stock and on sale for $179.99 including free shipping. Their price is $70 (28%) off MSRP, and it’s currently the lowest price available for new AirPods... Read more
Apple Magic Keyboards for iPads are on sale f...
Amazon has Apple Magic Keyboards for iPads on sale today for up to $70 off MSRP, shipping included: – Magic Keyboard for 10th-generation Apple iPad: $199, save $50 – Magic Keyboard for 11″ iPad Pro/... Read more
Apple’s 13-inch M2 MacBook Airs return to rec...
Apple retailers have 13″ MacBook Airs with M2 CPUs in stock and on sale this weekend starting at only $849 in Space Gray, Silver, Starlight, and Midnight colors. These are the lowest prices currently... Read more
Best Buy is clearing out iPad Airs for up to...
In advance of next week’s probably release of new and updated iPad Airs, Best Buy has 10.9″ M1 WiFi iPad Airs on record-low sale prices for up to $200 off Apple’s MSRP, starting at $399. Sale prices... Read more
Every version of Apple Pencil is on sale toda...
Best Buy has all Apple Pencils on sale today for $79, ranging up to 39% off MSRP for some models. Sale prices for online orders only, in-store prices may vary. Order online and choose free shipping... Read more
Sunday Sale: Apple Studio Display with Standa...
Amazon has the standard-glass Apple Studio Display on sale for $300 off MSRP for a limited time. Shipping is free: – Studio Display (Standard glass): $1299.97 $300 off MSRP For the latest prices and... Read more
Apple is offering significant discounts on 16...
Apple has a full line of 16″ M3 Pro and M3 Max MacBook Pros available, Certified Refurbished, starting at $2119 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free... Read more
Apple HomePods on sale for $30-$50 off MSRP t...
Best Buy is offering a $30-$50 discount on Apple HomePods this weekend on their online store. The HomePod mini is on sale for $69.99, $30 off MSRP, while Best Buy has the full-size HomePod on sale... Read more
Limited-time sale: 13-inch M3 MacBook Airs fo...
Amazon has the base 13″ M3 MacBook Air (8GB/256GB) in stock and on sale for a limited time for $989 shipped. That’s $110 off MSRP, and it’s the lowest price we’ve seen so far for an M3-powered... Read more
13-inch M2 MacBook Airs in stock today at App...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more

Jobs Board

Licensed Practical Nurse - Womens Imaging *A...
Licensed Practical Nurse - Womens Imaging Apple Hill - PRN Location: York Hospital, York, PA Schedule: PRN/Per Diem Sign-On Bonus Eligible Remote/Hybrid Regular Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
Operating Room Assistant - *Apple* Hill Sur...
Operating Room Assistant - Apple Hill Surgical Center - Day Location: WellSpan Health, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Read more
Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.