这是耿祥义教材上的例子(还有比这更强的你自己看看吧),绝对满足楼主的要求!
这种方法只能播放au格式的文件,wav的文件可以把后缀改成au也可以播放。而mp3、wma等格式就不能播放。
我也正在找呢你找到好的叫我一声哟!
给我分呀!!!import java.applet.*;import java.awt.*;
import java.awt.event.*;
public class Example24_2 extends Applet implements ActionListener,Runnable
{AudioClip clip;//声明一个音频对象。
 TextField text;Thread thread;
 Button button_play,button_loop,button_stop;
 public void init()
 { thread=new Thread(this);//创建一个新的线程。
   thread.setPriority(Thread.MIN_PRIORITY);
  button_play=new Button("开始播放"); button_loop=new Button("循环播放");
  button_stop=new Button("停止播放");  text=new TextField(12);
  button_play.addActionListener(this);
  button_stop.addActionListener(this);
  button_loop.addActionListener(this); 
  add(button_play);add(button_loop);add(button_stop);
  add(text);   
 } 
 public void start()
 {thread.start();}
 public void stop()
 {clip.stop();}//当离开此页面时停止播放。
 public void actionPerformed(ActionEvent e)
 {if(e.getSource()==button_play)
   { clip.play();}
  else if(e.getSource()==button_loop)
   { clip.loop();}
  if(e.getSource()==button_stop)
   { clip.stop();} 
 }
 public void run()
 { clip=getAudioClip(getCodeBase(),java中支持的播放类型);
    //在线程thread中创建音频对象。
   text.setText("请稍等...");
   if(clip!=null)
   {button_play.setBackground(Color.green);
    button_play.setBackground(Color.green);
    text.setText("您可以播放了");
    }//当获得音频对象后,通知客户可以播放了。
 }
}

解决方案 »

  1.   

    帮忙
    不知道这个对你有没有用哦
    http://big5.ccidnet.com:89/gate/big5/tech.ccidnet.com/pub/article/c340_a47658_p1.html
      

  2.   

    package jsounddemo1;import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    /**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2002</p>
     * <p>Company: </p>
     * @author unascribed
     * @version 1.0
     */public class MainFrame extends JFrame {
      private JPanel contentPane;
      private JTextField jTextField1 = new JTextField();
      private JLabel jLabel1 = new JLabel();
      private JPanel jPanel1 = new JPanel();
      private JButton jButton1 = new JButton();
      private JButton jButton2 = new JButton();  private java.applet.AudioClip clip;  //Construct the frame
      public MainFrame() {
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      //Component initialization
      private void jbInit() throws Exception  {
        //setIconImage(Toolkit.getDefaultToolkit().createImage(MainFrame.class.getResource("[Your Icon]")));
        contentPane = (JPanel) this.getContentPane();
        this.setSize(new Dimension(418, 118));
        this.setTitle("JSoundDemo1");
        jLabel1.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel1.setToolTipText("");
        jLabel1.setText("Waiting.........");
        jButton1.setFont(new java.awt.Font("Dialog", 0, 12));
        jButton1.setText("Play");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jButton1_actionPerformed(e);
          }
        });
        jButton2.setEnabled(false);
        jButton2.setFont(new java.awt.Font("Dialog", 0, 12));
        jButton2.setText("Stop");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jButton2_actionPerformed(e);
          }
        });
        jTextField1.setText(ClassLoader.getSystemResource("sounds/spacemusic.au").toString());
        contentPane.add(jLabel1, BorderLayout.SOUTH);
        contentPane.add(jPanel1, BorderLayout.CENTER);
        jPanel1.add(jButton1, null);
        jPanel1.add(jButton2, null);
        contentPane.add(jTextField1, BorderLayout.NORTH);    clip=null;
      }
      //Overridden so we can exit when window is closed
      protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
          System.exit(0);
        }
      }  void jButton1_actionPerformed(ActionEvent e) {
        try{
          jButton1.setEnabled(false);
          jButton2.setEnabled(true);
          clip = java.applet.Applet.newAudioClip(new java.net.URL(this.jTextField1.getText()));
    //      clip = java.applet.Applet.newAudioClip(ClassLoader.getSystemResource("sounds/spacemusic.au"));      clip.play();      this.jLabel1.setText("Now Playing "+this.jTextField1.getText());    }catch(Exception err){
          err.printStackTrace();
        }
      }  void jButton2_actionPerformed(ActionEvent e) {
        try{
          jButton1.setEnabled(true);
          jButton2.setEnabled(false);
          clip.stop();
          this.jLabel1.setText("Waiting .......");
        }catch(Exception err){
          err.printStackTrace();
        }
      }
    }
      

  3.   

    try to paly sound using JMF, paly .midi whose size is very small
      

  4.   

    楼上的willddy()刚刚做过,关于这一方面的应用,听听他的意见吧