Results 1 to 10 of 10
- 06-21-2012, 02:51 PM #1
Member
- Join Date
- Jun 2012
- Posts
- 7
- Rep Power
- 0
Need help with sound after countdown
Hey guys I am bussy makeing a countdown timer. Well I have the timer sorted out but now I want a sound to play when the time reaches 00:00. This is a code I got on another website. It works there but not when I put into my program.
This is what I have thus far.
if ("jLabel1"=="00:00")
{
throws Exception
String clip = "C:/Users/Th3L3gend/Desktop/alr.vaw";
InputStream in = new FileInputStream(clip);
AudioStream audio = new AudioStream(in);
AudioPlayer.player.start(audio);
}
At the if statement there is a measage that says "Comparing String using ==" how do I fix that?
And also when i run it says the file cannot be found "C:/Users/Th3L3gend/Desktop/alr.vaw";
There is a picture of what the programs looks like when it runs.
- 06-21-2012, 02:53 PM #2
Re: Need help with sound after countdown
When would that if statement ever evaluate to true? You're comparing two obviously different Strings. Is that a typo?
Don't use == when comparing Strings. Use the equals() method. Do a search on google or on these forums for a fuller explanation of why.
Is the file located at that location? Is everything spelled correctly, including capitalization?How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 06-21-2012, 09:56 PM #3
Member
- Join Date
- Jun 2012
- Posts
- 7
- Rep Power
- 0
Re: Need help with sound after countdown
Yeah I have made sure like 30 times i even copied the adress from the adress bar. I'll check out the eqaulsTo method thanx
- 06-21-2012, 10:08 PM #4
Re: Need help with sound after countdown
Yea, it looks like you are trying to get the text value of jLabel1, but you are comparing the literal value of "jLabel1" to "00:00", which as stated, will not evaluate to true. Two things to consider:
-use the .equals() method when comparing strings
-you need to extract the text value from jLabel1, and not compare the jLabel itself to "00:00"
- 06-21-2012, 10:15 PM #5
Member
- Join Date
- Jun 2012
- Posts
- 7
- Rep Power
- 0
Re: Need help with sound after countdown
So I have checked out the equals() method. But stil the same problem. I have ediit it a little more. Now it says incompatible tipes. This is my new code.
String sr = "00:00";
if ((jLabel1).equals(sr))
{
{
String clip = "C:/Users/Th3L3gend/Desktop/alr.vaw";
InputStream in = null;
try {
in = new FileInputStream(clip);
} catch (FileNotFoundException ex) {
Logger.getLogger(Countdown.class.getName()).log(Le vel.SEVERE, null, ex);
}
AudioStream audio = null;
try {
audio = new AudioStream(in);
} catch (IOException ex) {
Logger.getLogger(Countdown.class.getName()).log(Le vel.SEVERE, null, ex);
}
AudioPlayer.player.start(audio);
}
}
here is the code to update the diplayed time on the clock. How will I connect the two?
protected void process(List<String> times) {
String lastTime = times.get(times.size()-1);
jLabel1.setText(lastTime);Last edited by elbert.dewet@yahoo.com; 06-21-2012 at 10:27 PM.
- 06-21-2012, 10:19 PM #6
Re: Need help with sound after countdown
You are comparing an object of type JLabel(jLabel1) to an object of type String(sr).
You need to get the text value of jLabel1, and compare that value to sr.
- 06-21-2012, 10:20 PM #7
Re: Need help with sound after countdown
When you get error messages, please copy and paste the full text here.it says incompatible tipes.
Please edit your post and wrap the code in code tags.
BB Code List - Java Programming ForumIf you don't understand my response, don't ignore it, ask a question.
- 06-22-2012, 12:01 AM #8
Member
- Join Date
- Jun 2012
- Posts
- 7
- Rep Power
- 0
Re: Need help with sound after countdown
Hey thanx for advice I've found the problem works like a charm!
- 06-22-2012, 11:23 AM #9
Member
- Join Date
- Jun 2012
- Posts
- 7
- Rep Power
- 0
Re: Need help with sound after countdown
Haha so I've run into another problem. The sound plays and everything. But the main idee is to run this program on more than one pc. And in this codeing the path is specificaly for my pc. So how would I change the path so that it will run the sound from the folder the program is saved. I've pasted the .wav file into the same folder as the main project. And another thing is im useing exe4j program to make it a .exe file for windows. If I am able to fix the adress code will it be fine after converting it?
this is my codeing for the runnning of the sound. It works for the moment.
protected void process(List<String> times) {
String lastTime = times.get(times.size()-1);
jLabel1.setText(lastTime); // just update ui with lastTimer, ohters are ignorable
String sr = "00:00";
File sound;
if ((lastTime).equals(sr))
{
{
String clip = "C:/Users/Th3L3gend/Desktop/Counter sonder BUZZ/Countdowns/src/Sirčne.wav";
InputStream in = null;
try {
in = new FileInputStream(clip);
} catch (FileNotFoundException ex) {
Logger.getLogger(Countdown.class.getName()).log(Le vel.SEVERE, null, ex);
}
AudioStream audio = null;
try {
audio = new AudioStream(in);
} catch (IOException ex) {
Logger.getLogger(Countdown.class.getName()).log(Le vel.SEVERE, null, ex);
}
AudioPlayer.player.start(audio);
}
}
}
- 06-22-2012, 01:50 PM #10
Similar Threads
-
Countdown Program Help!
By alllks in forum New To JavaReplies: 6Last Post: 07-27-2012, 04:18 PM -
Java Countdown Timer
By JayB in forum New To JavaReplies: 2Last Post: 05-12-2011, 03:17 AM -
Problems with sound in java and USB sound card
By marblecatdog in forum New To JavaReplies: 1Last Post: 04-19-2011, 12:02 PM -
10 seconds countdown on console
By eLancaster in forum New To JavaReplies: 4Last Post: 04-08-2011, 06:46 PM -
CountDown timer
By Seema Sharma in forum AWT / SwingReplies: 1Last Post: 03-06-2008, 04:26 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks