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

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 »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »
Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links below... | Read more »
Marvel Future Fight celebrates nine year...
Announced alongside an advertising image I can only assume was aimed squarely at myself with the prominent Deadpool and Odin featured on it, Netmarble has revealed their celebrations for the 9th anniversary of Marvel Future Fight. The Countdown... | Read more »
HoYoFair 2024 prepares to showcase over...
To say Genshin Impact took the world by storm when it was released would be an understatement. However, I think the most surprising part of the launch was just how much further it went than gaming. There have been concerts, art shows, massive... | Read more »

Price Scanner via MacPrices.net

Amazon is offering a $100 discount on every M...
Amazon is offering a $100 instant discount on each configuration of Apple’s new 13″ M3 MacBook Air, in Midnight, this weekend. These are the lowest prices currently available for new 13″ M3 MacBook... Read more
You can save $300-$480 on a 14-inch M3 Pro/Ma...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
24-inch M1 iMacs available at Apple starting...
Apple has clearance M1 iMacs available in their Certified Refurbished store starting at $1049 and ranging up to $300 off original MSRP. Each iMac is in like-new condition and comes with Apple’s... Read more
Walmart continues to offer $699 13-inch M1 Ma...
Walmart continues to offer new Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBook for sale by... Read more
B&H has 13-inch M2 MacBook Airs with 16GB...
B&H Photo has 13″ MacBook Airs with M2 CPUs, 16GB of memory, and 256GB of storage in stock and on sale for $1099, $100 off Apple’s MSRP for this configuration. Free 1-2 day delivery is available... Read more
14-inch M3 MacBook Pro with 16GB of RAM avail...
Apple has the 14″ M3 MacBook Pro with 16GB of RAM and 1TB of storage, Certified Refurbished, available for $300 off MSRP. Each MacBook Pro features a new outer case, shipping is free, and an Apple 1-... Read more
Apple M2 Mac minis on sale for up to $150 off...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for $100-$150 off MSRP, each including free delivery: – Mac mini M2/256GB SSD: $499, save $100 – Mac mini M2/512GB SSD: $699, save $100 –... Read more
Amazon is offering a $200 discount on 14-inch...
Amazon has 14-inch M3 MacBook Pros in stock and on sale for $200 off MSRP. Shipping is free. Note that Amazon’s stock tends to come and go: – 14″ M3 MacBook Pro (8GB RAM/512GB SSD): $1399.99, $200... Read more
Sunday Sale: 13-inch M3 MacBook Air for $999,...
Several Apple retailers have the new 13″ MacBook Air with an M3 CPU in stock and on sale today for only $999 in Midnight. These are the lowest prices currently available for new 13″ M3 MacBook Airs... Read more
Multiple Apple retailers are offering 13-inch...
Several 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... Read more

Jobs Board

Relationship Banker - *Apple* Valley Financ...
Relationship Banker - Apple Valley Financial Center APPLE VALLEY, Minnesota **Job Description:** At Bank of America, we are guided by a common purpose to help Read more
IN6728 Optometrist- *Apple* Valley, CA- Tar...
Date: Apr 9, 2024 Brand: Target Optical Location: Apple Valley, CA, US, 92308 **Requisition ID:** 824398 At Target Optical, we help people see and look great - and Read more
Medical Assistant - Orthopedics *Apple* Hil...
Medical Assistant - Orthopedics Apple Hill York Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Now 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
Liquor Stock Clerk - S. *Apple* St. - Idaho...
Liquor Stock Clerk - S. Apple St. Boise Posting Begin Date: 2023/10/10 Posting End Date: 2024/10/14 Category: Retail Sub Category: Customer Service Work Type: Part Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.