Home > Articles > Programming > Java

  • Print
  • + Share This
From the author of

Run the Program

Once you've successfully compiled the source code, you can run the MediaPlayer application. To run MediaPlayer, specify the following command line at a command prompt:

java MediaPlayer

Assuming successful execution, you'll see the main window (refer to Figure 1). To play a media file, all you need to do is select Open... from the File menu and choose a media file (such as an MPEG or MP3) from the resulting Open File dialog box. As soon as you click the Open File dialog box's Open button, the media file is loaded, appropriate visual and/or control panel components are displayed, and the media starts playing. Figure 4 shows one frame of an MPEG movie being played by MediaPlayer. (The frame is displayed by the visual component.)

Figure 4

The media player (at least under Windows with the Windows performance pack) can play MPEG movies, such as a movie that presents a mosaic of the Orion nebula.

If the Loop menu item is unchecked (which is the default), the media doesn't automatically restart once it finishes playing. You have to manually restart the media by manipulating the media control panel. To initiate looping, make sure that the Loop menu item is checked (by selecting this menu item), and then reload the media file.

If you encounter execution problems, note that you might have set your CLASSPATH environment variable to something other than the current directory, represented by a single period (.) character under Windows. If this is the case, you can correct the problem by appending a semicolon (;) character followed by a period (.) character to your CLASSPATH setting—that is, set classpath=%classpath%;. (under Windows).

  • + Share This
  • 🔖 Save To Your Account