Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

13. Graphics and Sound > 13.10. Playing a Video Clip

13.10. Playing a Video Clip

Problem

You want to display a video file within a Java program.

Solution

Use the Java Media Framework (JMF), a standard extension.

Discussion

Example 13-5 shows a program that displays a movie or other media file named on the command line. JMF is very flexible; this program plays an audio file, supplying a volume control if the media object that you name contains a sound clip instead of a movie. Figure 13-6 shows JMFPlayer displaying a sound file and a movie.

JMFPlayer in action: audio (left), video (right)

Figure 13-6. JMFPlayer in action: audio (left), video (right)

Example 13-5. JMFPlayer.java

import com.darwinsys.util.WindowCloser;

import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.net.*;
import java.io.*;
import java.util.*;
import javax.media.*;

/**
 * Demonstrate simple code to play a movie with Java Media Framework.
 */
public class JMFPlayer extends JPanel implements ControllerListener {

    /** The player object */
    Player thePlayer = null;
    /** The parent Frame we are in. */
    JFrame parentFrame = null;
    /** Our contentpane */
    Container cp;
    /** The visual component (if any) */
    Component visualComponent = null;
    /** The default control component (if any) */
    Component controlComponent = null;
    /** The name of this instance's media file. */
    String mediaName;
  ....

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint