如果不能播放.ram .rm 和 .wma .wmv文件,并且不是所有MP3文件都能放(和压缩方式有关)你还会考虑用JAVA来做播放器吗?

解决方案 »

  1.   

    我只要求能播放MPEG图象就够了。
      

  2.   

    先下载jmf.jar
    使用javax.media包就可以了。
    看看我的例子吧
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.net.*;
    import java.io.*;
    import javax.media.*;/**
     * <p>Title: 雷堂祖聊天软件</p>
     * <p>Description: 雷堂祖</p>
     * <p>Copyright: Copyright (c) 2003</p>
     * <p>Company: 雷堂祖</p>
     * @author 雷堂祖([email protected])
     * @version 1.0
     */public class BasicPlayer extends Applet implements ControllerListener
    {
      boolean isStandalone = false;
      String mediaFile;
      //Get a parameter value
      public String getParameter(String key, String def)
      {
        return isStandalone ? System.getProperty(key, def) :
          (getParameter(key) != null ? getParameter(key) : def);
      }
      Player player = null;
      Component visualComponent = null;  //Construct the applet
      public BasicPlayer()
      {
      }
      //Initialize the applet
      public void init()
      {
        try
        {
          mediaFile = this.getParameter("MediaFile", "");
        }
        catch(Exception e)
        {
          e.printStackTrace();
        }
        try
        {
          jbInit();
        }
        catch(Exception e)
        {
          e.printStackTrace();
        }
      }
      //Component initialization
      private void jbInit() throws Exception
      {
        URL mediaURL =  null;    setLayout(new BorderLayout());
        if(mediaFile == null)
        {
          System.err.print("MediaFile not present.");
          System.err.println("Required parameter is 'MediaFile'");
        }
        else
        {
          try{
              mediaURL = new URL(this.getDocumentBase(),mediaFile);          player = Manager.createPlayer(mediaURL);          if(player !=null)
              {
                  player.addControllerListener(this);
              }else{
                  System.err.println("failed to create player for "+mediaFile);
              }
          }
          catch(IOException e)
          {
            System.err.println("URL for "+mediaFile +" is invalid");
          }
          catch(NoPlayerException e)
          {
            System.err.println("could not find a player for "+mediaURL);
          }
        }  }
      //Start the applet
      public void start()
      {
        if(player != null)
        {
          player.prefetch();
        }
      }
      //Stop the applet
      public void stop()
      {
        if(player != null)
        {
          player.stop();
          player.deallocate();
        }
      }
      //Destroy the applet
      public void destroy()
      {
      }
      //Get Applet information
      public String getAppletInfo()
      {
        return "Applet Information";
      }
      //Get parameter info
      public String[][] getParameterInfo()
      {
        String[][] pinfo =
          {
          {"MediaFile", "String", "./images/0050.mpg"},
          };
        return pinfo;
      }
      public void componentAdded(ContainerEvent e)
      {
        /**@todo: Implement this java.awt.event.ContainerListener method*/
        //throw new java.lang.UnsupportedOperationException("Method componentAdded() not yet implemented.");
      }
      public void componentRemoved(ContainerEvent e)
      {
        /**@todo: Implement this java.awt.event.ContainerListener method*/
        //throw new java.lang.UnsupportedOperationException("Method componentRemoved() not yet implemented.");
      }
      public synchronized void controllerUpdate(ControllerEvent parm1)
      {
        /**@todo: Implement this javax.media.ControllerListener method*/
        //throw new java.lang.UnsupportedOperationException("Method controllerUpdate() not yet implemented.");
        if(parm1 instanceof RealizeCompleteEvent)
        {
          if((visualComponent = player.getVisualComponent()) != null)
          {
            this.add("Center",visualComponent);
          }
          this.validate();
        }else{
          if(parm1 instanceof PrefetchCompleteEvent)
          {
            player.start();
          }
        }
      }
    }
      

  3.   

    上面的程序就支持internet文件,修改mediafile即可