看看JMF
http://servlet.java.sun.com/javaone/conf/bofs/845/0-sf2001.jsp
应该可以实现你说的功能

解决方案 »

  1.   

    是的,你可以使用Sun公司发布的专门用于多媒体应用的一组API--Java Media Frame.你可以到http://java.sun.com/products/java-media/jmf/下载最新版本.
    我有例程,你可以给我发信:[email protected]
      

  2.   

    谢谢2位.
    可是,我是要做Applet啊...
    要把JMF也打包到Applet里吗?
    我只是想播放一个声音文件,播放完毕后,调页面中javascript函数,通知javascript
    这就足够了
    用JMF感觉大材小用了似的用Applet不能解决的就是,AudioClip播放是异步的
    我想要同步的,或者有事件都行.Applet是否不能解决这个问题啊?再次对2位帮助表示感谢.
      

  3.   

    楼主敬请参阅:http://expert.csdn.net/Expert/topic/1130/1130312.xml?temp=.3366815还有例子:import java.applet.*; 
    import java.awt.*; 
    import java.awt.event.*; 
    public class Pf extends Applet implements ActionListener {
    AudioClip clip; 
    Button button_play,button_loop,button_stop; 

    public void init() 
    {//getAudioClip(),getCodeBase()是Applet的方法
    clip=getAudioClip(getCodeBase(),"sound01.wav"); 
    button_play=new Button("开始"); 
    button_loop=new Button("循环"); 
    button_stop=new Button("停止"); 
    button_play.addActionListener(this); 
    button_loop.addActionListener(this); 
    button_stop.addActionListener(this); 
    add(button_play);add(button_loop);add(button_stop);

    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();

    }
      

  4.   

    import java.awt.Graphics;
    import java.applet.AudioClip;
    public class AudioLoop extends java.applet.Applet implements Runnable
    {
      AudioClip bgsound;
      AudioClip beep;
      Thread runner;
      public void start()
    {
      if(runner==null)
    {
      runner=runner=new Thread(this);
      runner.start();
    }}
    public void stop()
    {
      if(runner!=null)
    {
      if(bgsound!=null)
      runner.stop();
      runner==null;
    }
    }
    public viod init()
    {
      bgsound=getAudioClip(getCodeBase()."audio/loop.au");
      beep=getAudioClip(getCodeBase(),"audio/beep,au");
    }
    public void run()
    {
      if(bgsound!=null)bgsound.loop();
      while(runner!=null)
    {
    try
    {
    Thread.sleep(100);
    catch(InterruptedException e)
    {}
    if(bgsound!=null)
      bgsound.play();
    }
    }
    }
    public void paint(Graphics g)
    {
    g.drawString("Playing Sound",10,10);
    }
    }
      

  5.   

    可能我还是没表述清楚,我需要的是:
    我举一个例子:三个audio file
    a.au b.au c.au我需要用applet播放这3个声音
    是依此播放,播放完a,然后b,然后c
    audioclip不提供播放完毕的通知功能
    如果分别写3个play,那么就会导致3个一起放
    而我要的是分别,依此播放还有一个问题就是我想,播放a.au c.au
    b.au不播放,但是中间要停播放b.au的声音那么长的时间...
    今天我终于找到了sun的文档,上面说,这需要
    得到clip 的length,然后sleep那么长
    时间可是,,问题是,怎么才知道一个AudioClip的长度?anyone can help me?
      

  6.   

    PS:
    document from sun:Problem: I want to play several sound files in succession from an applet. However, when I use play two times after each other they just get mixed up. 
    Unfortunately, the Java 2 SDK does not provide notification of when playback has completed. The Java Sound API provides this feature. It is available as an early access release. If you must use the SDK, you could try to determine the length of each clip and sleep for the same about of time before playing the next clip.