Introduction

Although the Open Source Physics (OSP) framework is designed primarily for building simulations and animations, there are good reasons to include video as well. When a simulation is saved as a video or animated gif it can be transmitted and played almost anywhere. A video can also be a background for an animation: videos of real world phenomena can be overlaid with model animations, for example, or animation videos can be overlaid with other animations.

Figure 1. Video and the OSP Media Framework

OSP video

The OSP media framework, defined in the org.opensourcephysics.media package, provides the classes needed for creating, playing and analyzing digital videos and animated gifs. Sample programs are located in the org.opensourcephysics.mediaapps package. The media framework is also the basis for Tracker, a full-featured video analysis application available at http://www.cabrillo.edu/~dbrown/tracker.

This tutorial is designed for developers with some knowledge of Java and the OSP framework who wish to create applications and applets for physics education. It includes Java code fragments and complete applications.

Note: descriptions of interfaces and classes in this tutorial are for illustrative purposes only, and include only commonly used and/or typical methods. For complete documentation, see the media JavaDocs.

Important: QuickTime 6, including QuickTime for Java, must be installed on the local computer in order to open QuickTime and AVI movies. The installer can be downloaded from http://www.apple.com/quicktime/download/. When installing, you should select Custom Installation and ensure that QuickTime for Java is checked. It is recommended that all QuickTime components be installed.

The org.opensourcephysics.media.quicktime package includes QT, a utility class that provides static methods for managing QuickTime resources. Generally, the only methods needed by OSP developers are QT.exit(), which immediately releases QuickTime resources, and QT.exitOnClose(java.awt.Frame), which calls QT.exit() when the specified frame is closed. The direct call to QT.exit() is particularly useful in applets, where it can be included in the Applet.destroy() method. Applications that use QuickTime must call QT.exit() either directly or indirectly through QT.exitOnClose().