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");
}
System.out.println("No File Found");
}
But I cannot hear the sound in JBX
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
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
怎么把该线程结束呢?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
boolean i = AudioPlayer.player.isAlive();//你在这一行加一下断点,看一看就知道事实上audioPlayer.player是AudioPlayer另开的一个线程,其实在你调用stop(as)后,它没有被停止.
不过因为AudioPlayer我这里没有它的资料,所以更深一层也不能给你解答了.
or else, I have to change to javax.sound.