What do you mean by "no response"?I tried your codes in JBX but everything goes well.I suggest you to write something in the catches, ie}catch(FileNotFoundException fn){
  System.out.println("No File Found");
}

解决方案 »

  1.   

    it said "No File Found" , but iI have a file "2.wav" in the same folder with this .java file.I directly run the .java file in JCreator, then I can hear the sound of "2.wav".
    But I cannot hear the sound in JBX
      

  2.   

    I add my route path, then it works.
    inStreamObj = new FileInputStream("..\\MegacoClient8.1\\src\\megacoclient\\protocol\\tool\\2.wav");
    why in JCreator, I only need write the file name?
    route path is always changeable, how can I deal with it and just write the file name
      

  3.   

    The answer is simple
    You should put the 2.wav into the base directiory, ie
    If your project.prj locates in the F:\sound\project.prj
    then you should put the 2.wav at here F:\sound\2.wav
      

  4.   

    谢谢,还是上面的程序:改进。发现放完声音,程序并不停止。我试过stop,destroy都不行
    怎么把该线程结束呢?import java.io.*;         // required for accessing the wave file
    import sun.audio.*;       // required for sound in an application
    public class CallSound extends Thread {  public int m_soundIndex;
      public boolean m_soundStop=false;  public CallSound(int i) {
        this.m_soundIndex = i;
      }  public void stopPlay() {
        this.m_soundStop=true;
      }
      public void run(){    try {
          System.out.println("begining play..."); //@@@@@@@@@@@
          FileInputStream inStreamObj = null;
          switch (this.m_soundIndex) {
            case 1:
              inStreamObj = new FileInputStream
                  ("1.wav");
              break;
            case 2:
              inStreamObj = new FileInputStream
                  ("2.wav");
              break;
            case 3:
              inStreamObj = new FileInputStream
                  ("3.wav");
              break;
            case 4:
              inStreamObj = new FileInputStream
                  ("4.wav");
              break;
            case 5:
              inStreamObj = new FileInputStream
                  ("5.wav");
              break;
            case 6:
              inStreamObj = new FileInputStream
                  ("6.wav");
              break;
            case 7:
              inStreamObj = new FileInputStream
                  ("7.wav");
              break;
            case 8:
              inStreamObj = new FileInputStream
                  ("8.wav");
              break;
          }      // Create an AudioStream object from the FileInputStream object.
          AudioStream as = new AudioStream(inStreamObj);      AudioPlayer.player.start(as);      //keep checking and stop playing sound
          while(true)
          {
            if(this.m_soundStop)
             {
               AudioPlayer.player.stop(as);
               break;
             }
          }      System.out.println("finish play..."); //@@@@@@@@    }
        catch (FileNotFoundException fn) {      fn.printStackTrace();    }
        catch (IOException io) {      io.printStackTrace();
        }  }  public static void main (String[] args)
      {
        CallSound cs= new CallSound(1);
        cs.start();
        try{
          BufferedReader userInput
              = new BufferedReader(new InputStreamReader(System.in));
          String number = userInput.readLine();
          // input "s" stop
          if(number.equalsIgnoreCase("s"))
          cs.stopPlay();
        }catch(IOException sd){
          sd.printStackTrace();
        }
      }
    } // end of class
      

  5.   

    System.out.println("finish play..."); //@@@@@@@@
         boolean i = AudioPlayer.player.isAlive();//你在这一行加一下断点,看一看就知道事实上audioPlayer.player是AudioPlayer另开的一个线程,其实在你调用stop(as)后,它没有被停止.
         不过因为AudioPlayer我这里没有它的资料,所以更深一层也不能给你解答了.
      

  6.   

    I know audioPlayer.player是AudioPlayer另开的一个线程, but how can I destory it.why destory dosen't work?
    or else, I have to change to javax.sound.
      

  7.   

    in JDK1.5.0.stop works, I am sure it is a bug in JDK 1.4
      

  8.   

    but I still need a solution
      

  9.   

    Look my code, send it to your e-mail