/**

 * Description: Simple Multimedia Player

 * Date: November 25,2007

 * @author Kevin Haghighat

 * @version 1.0

 * Purpose: This code is a companion to the Java Media Frameworks (an introduction) paper.

 **/

public class Simple_Multimedia_Player {

  public static void main (String[] args) {

    try {

      // create a JFrame to display the Player.

      final javax.swing.JFrame myFrame = new javax.swing.JFrame ("Simple Multimedia Player");

      myFrame.setDefaultCloseOperation (javax.swing.JFrame.EXIT_ON_CLOSE);

      myFrame.setDefaultLookAndFeelDecorated(true);

      myFrame.setSize(200, myFrame.getHeight());

      myFrame.setVisible(true);

      java.net.URL myURL = new java.net.URL (args[0].trim());      // get the URL path to the media file.

      final javax.media.Player myPlayer = javax.media.Manager.createPlayer (myURL);  // create the Player.

      myPlayer.addControllerListener (new javax.media.ControllerListener () {  // add listener to the Player.

        public void controllerUpdate (javax.media.ControllerEvent myControllerEvent) {

          if (myControllerEvent instanceof javax.media.RealizeCompleteEvent) {

            // get and add the control panel component of the Player to the JFrame.

            java.awt.Component myControlPanelComponent = myPlayer.getControlPanelComponent();

            myFrame.getContentPane().add(myControlPanelComponent, java.awt.BorderLayout.SOUTH);

            // get and add the visual component of the Player, if any, to the JFrame.

            java.awt.Component myVisualComponent = myPlayer.getVisualComponent ();

            if (myVisualComponent != null )

              myFrame.getContentPane().add(myVisualComponent, java.awt.BorderLayout.CENTER);

            myFrame.pack ();            // resize the JFrame to fit and show the added components.

            myPlayer.start();           // start the Player.

          }

        }

      }

      );

      myPlayer.realize();

    } catch (Exception e) { System.exit(0); }

  }

}

