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

Tokkun Studio unveils alpha trailer for...
We are back on the MMORPG news train, and this time it comes from the sort of international developers Tokkun Studio. They are based in France and Japan, so it counts. Anyway, semantics aside, they have released an alpha trailer for the upcoming... | Read more »
Win a host of exclusive in-game Honor of...
To celebrate its latest Jujutsu Kaisen crossover event, Honor of Kings is offering a bounty of login and achievement rewards kicking off the holiday season early. [Read more] | Read more »
Miraibo GO comes out swinging hard as it...
Having just launched what feels like yesterday, Dreamcube Studio is wasting no time adding events to their open-world survival Miraibo GO. Abyssal Souls arrives relatively in time for the spooky season and brings with it horrifying new partners to... | Read more »
Ditch the heavy binders and high price t...
As fun as the real-world equivalent and the very old Game Boy version are, the Pokemon Trading Card games have historically been received poorly on mobile. It is a very strange and confusing trend, but one that The Pokemon Company is determined to... | Read more »
Peace amongst mobile gamers is now shatt...
Some of the crazy folk tales from gaming have undoubtedly come from the EVE universe. Stories of spying, betrayal, and epic battles have entered history, and now the franchise expands as CCP Games launches EVE Galaxy Conquest, a free-to-play 4x... | Read more »
Lord of Nazarick, the turn-based RPG bas...
Crunchyroll and A PLUS JAPAN have just confirmed that Lord of Nazarick, their turn-based RPG based on the popular OVERLORD anime, is now available for iOS and Android. Starting today at 2PM CET, fans can download the game from Google Play and the... | Read more »
Digital Extremes' recent Devstream...
If you are anything like me you are impatiently waiting for Warframe: 1999 whilst simultaneously cursing the fact Excalibur Prime is permanently Vault locked. To keep us fed during our wait, Digital Extremes hosted a Double Devstream to dish out a... | Read more »
The Frozen Canvas adds a splash of colou...
It is time to grab your gloves and layer up, as Torchlight: Infinite is diving into the frozen tundra in its sixth season. The Frozen Canvas is a colourful new update that brings a stylish flair to the Netherrealm and puts creativity in the... | Read more »
Back When AOL WAS the Internet – The Tou...
In Episode 606 of The TouchArcade Show we kick things off talking about my plans for this weekend, which has resulted in this week’s show being a bit shorter than normal. We also go over some more updates on our Patreon situation, which has been... | Read more »
Creative Assembly's latest mobile p...
The Total War series has been slowly trickling onto mobile, which is a fantastic thing because most, if not all, of them are incredibly great fun. Creative Assembly's latest to get the Feral Interactive treatment into portable form is Total War:... | Read more »

Price Scanner via MacPrices.net

Early Black Friday Deal: Apple’s newly upgrad...
Amazon has Apple 13″ MacBook Airs with M2 CPUs and 16GB of RAM on early Black Friday sale for $200 off MSRP, only $799. Their prices are the lowest currently available for these newly upgraded 13″ M2... Read more
13-inch 8GB M2 MacBook Airs for $749, $250 of...
Best Buy has Apple 13″ MacBook Airs with M2 CPUs and 8GB of RAM in stock and on sale on their online store for $250 off MSRP. Prices start at $749. Their prices are the lowest currently available for... Read more
Amazon is offering an early Black Friday $100...
Amazon is offering early Black Friday discounts on Apple’s new 2024 WiFi iPad minis ranging up to $100 off MSRP, each with free shipping. These are the lowest prices available for new minis anywhere... Read more
Price Drop! Clearance 14-inch M3 MacBook Pros...
Best Buy is offering a $500 discount on clearance 14″ M3 MacBook Pros on their online store this week with prices available starting at only $1099. Prices valid for online orders only, in-store... Read more
Apple AirPods Pro with USB-C on early Black F...
A couple of Apple retailers are offering $70 (28%) discounts on Apple’s AirPods Pro with USB-C (and hearing aid capabilities) this weekend. These are early AirPods Black Friday discounts if you’re... Read more
Price drop! 13-inch M3 MacBook Airs now avail...
With yesterday’s across-the-board MacBook Air upgrade to 16GB of RAM standard, Apple has dropped prices on clearance 13″ 8GB M3 MacBook Airs, Certified Refurbished, to a new low starting at only $829... Read more
Price drop! Apple 15-inch M3 MacBook Airs now...
With yesterday’s release of 15-inch M3 MacBook Airs with 16GB of RAM standard, Apple has dropped prices on clearance Certified Refurbished 15″ 8GB M3 MacBook Airs to a new low starting at only $999.... Read more
Apple has clearance 15-inch M2 MacBook Airs a...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs now available starting at $929 and ranging up to $410 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at... Read more
Apple drops prices on 13-inch M2 MacBook Airs...
Apple has dropped prices on 13″ M2 MacBook Airs to a new low of only $749 in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, now available for $679 for 8-Core CPU/7-Core GPU/256GB models. Apple’s one-year warranty is included, shipping is free, and each... Read more

Jobs Board

Seasonal Cashier - *Apple* Blossom Mall - J...
Seasonal Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Seasonal Fine Jewelry Commission Associate -...
…Fine Jewelry Commission Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) Read more
Seasonal Operations Associate - *Apple* Blo...
Seasonal Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Read more
Hair Stylist - *Apple* Blossom Mall - JCPen...
Hair Stylist - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom 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
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.