Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Default 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.

    Need help with sound after countdown-countdown.png

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,839
    Rep Power
    8

    Default 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!

  3. #3
    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Default 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

  4. #4
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    350
    Rep Power
    5

    Default 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"

  5. #5
    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Default 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.

  6. #6
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    350
    Rep Power
    5

    Default 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.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,274
    Rep Power
    25

    Default Re: Need help with sound after countdown

    it says incompatible tipes.
    When you get error messages, please copy and paste the full text here.

    Please edit your post and wrap the code in code tags.
    BB Code List - Java Programming Forum
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Default Re: Need help with sound after countdown

    Hey thanx for advice I've found the problem works like a charm!

  9. #9
    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Default 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);
    }
    }
    }

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Need help with sound after countdown

    Quote Originally Posted by elbert.dewet@yahoo.com View Post
    this is my codeing
    Do you read the responses?
    Quote Originally Posted by Norm View Post
    Please edit your post and wrap the code in code tags.
    BB Code List - Java Programming Forum
    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Countdown Program Help!
    By alllks in forum New To Java
    Replies: 6
    Last Post: 07-27-2012, 04:18 PM
  2. Java Countdown Timer
    By JayB in forum New To Java
    Replies: 2
    Last Post: 05-12-2011, 03:17 AM
  3. Problems with sound in java and USB sound card
    By marblecatdog in forum New To Java
    Replies: 1
    Last Post: 04-19-2011, 12:02 PM
  4. 10 seconds countdown on console
    By eLancaster in forum New To Java
    Replies: 4
    Last Post: 04-08-2011, 06:46 PM
  5. CountDown timer
    By Seema Sharma in forum AWT / Swing
    Replies: 1
    Last Post: 03-06-2008, 04:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •