I have made a media player in java using jmf which plays mp3,midi,mpeg1,mpeg2&avi.
How to play the mpeg4.Also i want to make a playlist for it which can add,delete and save the songs in the playlist.here is my code of media player.....

import javax.media.*;

import java.awt.*;
import java.awt.event.*;

class MediaPlayer extends Frame implements ActionListener,
                                           ControllerListener,
                                           ItemListener
{
   Player player;
   Component vc, cc;
   boolean first = true, loop = false;
   Image image;
   
   String currentDirectory;

   MediaPlayer (String title)
   {
      super (title);

      addWindowListener
                (new WindowAdapter ()
                 {
                     public void windowClosing (WindowEvent e)
                     {
                        // User selected close from System menu.
                        // Call dispose to invoke windowClosed.

                        dispose ();
                     }

                     public void windowClosed (WindowEvent e)
                     {
                        if (player != null)
                            player.close ();

                        System.exit (0);  
                     }
                 });

      Menu m = new Menu ("File");

      MenuItem mi = new MenuItem ("Open...");
      mi.addActionListener (this);
      m.add (mi);

      m.addSeparator ();

      CheckboxMenuItem cbmi = new CheckboxMenuItem ("Loop", false);
      cbmi.addItemListener (this);
      m.add (cbmi);

      m.addSeparator ();

      mi = new MenuItem ("Exit");
      mi.addActionListener (this);
      m.add (mi);

      MenuBar mb = new MenuBar ();
      mb.add (m);
      setMenuBar (mb);

      setSize (600, 200);

      setVisible (true);
   }

   public void actionPerformed (ActionEvent e)
   {
      if (e.getActionCommand ().equals ("Exit"))
      {
          // Call dispose to invoke windowClosed.

          dispose ();
          return;
      }

      FileDialog fd = new FileDialog (this, "Open File",
                                      FileDialog.LOAD);
      fd.setDirectory (currentDirectory);
      fd.show ();

      // If user cancelled, exit.

      if (fd.getFile () == null)
          return;

      currentDirectory = fd.getDirectory ();

      if (player != null)
          player.close ();

      try
      {
         player = Manager.createPlayer (new MediaLocator
                                           ("file:" +
                                            fd.getDirectory () +
                                            fd.getFile ()));
      }
      catch (java.io.IOException e2)
      {
         System.out.println (e2);
         return;
      }
      catch (NoPlayerException e2)
      {
         System.out.println ("Could not find a player.");
         return;
      }

      if (player == null)
      {
          System.out.println ("Trouble creating a player.");
          return;
      }

      first = false;

      setTitle (fd.getFile ());

      player.addControllerListener (this);
      player.prefetch ();
   }

   public void controllerUpdate (ControllerEvent e)
   {
     

      if (e instanceof ControllerClosedEvent)
      {
          if (vc != null)
          {
              remove (vc);
              vc = null;
          }

          if (cc != null)
          {
              remove (cc);
              cc = null;
          }

          return;
      }

      if (e instanceof EndOfMediaEvent)
      {
          if (loop)
          {
              player.setMediaTime (new Time (0));
              player.start ();
          }

          return;
      }

      if (e instanceof PrefetchCompleteEvent)
      {
          player.start ();
          return;
      }

      if (e instanceof RealizeCompleteEvent)
      {
          vc = player.getVisualComponent ();
          if (vc != null)
              add (vc);

          cc = player.getControlPanelComponent ();
          if (cc != null)
              add (cc, BorderLayout.SOUTH);

          pack ();
      }
   }

   public void itemStateChanged (ItemEvent e)
   {
      loop = !loop;
   }

   public void paint (Graphics g)
   {
      if (first)
      {
          int w = getSize ().width;
          int h = getSize ().height;

          //g.setColor (Color.black);
          //g.fillRect (0, 0, w, h);

          //Font f = new Font ("Swis721 BdOul BT" , Font.BOLD, 56);
          //g.setFont (f);
          image=new Image("E:/wallpapers/3D Wallpaper_Links.jpg");
          //FontMetrics fm = g.getFontMetrics ();
          //int swidth = fm.stringWidth ("jMedia+");
           image.getSource();
           
          //g.setColor (Color.green);
          //g.drawString ("jMedia+",
                       // (w - swidth) / 2,
                       // (h + getInsets ().top) / 2);
      }

     

      super.paint (g);
   }

  

   public void update (Graphics g)
   {
      paint (g);
   }

   public static void main (String [] args)
   {
      new MediaPlayer (" jMedia+ ");
   }
}

Also guide me for making the playlist

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.