package vidio;
import javax.media.*;
import javax.media.format.*;
import javax.media.protocol.*;import java.awt.*;
import java.awt.event.*;/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */public class VideoPlayer1  extends Frame implements ControllerListener,
    ActionListener{
  Player videoPlayer;  String filename;  /** creates new VideoPlayer1*/
  public VideoPlayer1(String s1) {
    super(s1);    //handler window event handler
    addWindowListener(new WindowAdapter()
                      {
                        public void windowClosing(WindowEvent e)
                        {
                          dispose();
                          System.exit(0);
                        }
                      });    //create the menu
    MenuBar mb = new MenuBar();
    setMenuBar(mb);
    Menu fileMenu = new Menu("File");
    mb.add(fileMenu);    MenuItem itemPlay = new MenuItem("Play");
    itemPlay.addActionListener(this);
    fileMenu.add(itemPlay);    MenuItem itemStop = new MenuItem("Stop");
    itemStop.addActionListener(this);
    fileMenu.add(itemStop);    MenuItem itemExit = new MenuItem("Exit");
    itemExit.addActionListener(this);
    fileMenu.add(itemExit);
    this.validate();
    this.setVisible(true);
  }  //add the event handler  public void actionPerformed(ActionEvent e)
  {
    String action = e.getActionCommand().toString();
    if (action.equals("Play"))
    {
      play();
    }
    if (action.equals("Stop"))
    {
     stop();
    }
    if (action.equals("Exit"))
    {
      dispose();
      System.exit(0);
    }  }  private void stop()
  {
    if (videoPlayer != null)
    {
      videoPlayer.stop();
    }
  }  private void play()
  {
    try{
      FileDialog fd = new FileDialog(this, "Choose Video",FileDialog.LOAD);
      fd.show();      //assemble the filename
      filename = fd.getDirectory() + fd.getFile();      //create the player
      videoPlayer = Manager.createPlayer(new MediaLocator("file:///" +
                                                             filename));
      //add a listener for player state changes
      videoPlayer.addControllerListener(this);      videoPlayer.start();
    }catch(Exception e)
    {
      System.out.println("Error"+e);
    }
  }// end play function
  public synchronized void controllerUpdate(ControllerEvent event)
  {
    System.out.println("Event: "+event);    if (event instanceof RealizeCompleteEvent)
    {
      Component comp;      if ((comp = videoPlayer.getVisualComponent()) != null)
      {
        add("Center",comp);
      }else{
        System.out.println("Unable to get visual component");
      }      if ((comp = videoPlayer.getControlPanelComponent()) != null)
      {
        add("South",comp);
      }      validate();
    }
  }  public static void main(String[] args) {
     VideoPlayer1 vp1 = new VideoPlayer1("videoPlayer1");     // show the frame containing the video
     vp1.setSize(300,300);
     vp1.setLocation(250,300);
  }
}