Loading...
Logo
Processing Forum
Copy code
    Copy code
    1. import ddf.minim.*;
    2. import ddf.minim.signals.*;
    3. import ddf.minim.analysis.*;
    4. import ddf.minim.effects.*;
    5. PFont menuFont;

    6. AudioPlayer mSound;
    7. Minim mSoundLoader;

    8. int mouseSound = -1;
    9. void setup ()
    10. {
    11.   precacheSound();
    12.   menuFont = loadFont("Perpetua-32.vlw");
    13. }

    14. void draw ()
    15. {
    16.  selectableText("Test", 50, 50, 1);
    17. }
    18. boolean highlighted (float x, float y, float x2, float y2)
    19. {
    20.   if (mouseX >= x && mouseX <= x2 && mouseY >= y && mouseY <= y2)
    21.     return true;
    22.     
    23.   return false;
    24. }

    25. void selectableText (String words, float xPos, float yPos, int soundNum)
    26. {
    27.   textFont(menuFont, 32);
    28.   
    29.   if (highlighted(xPos, yPos - textAscent(), xPos + textWidth(words), yPos + textDescent()))
    30.   {
    31.     fill(255);
    32.     if (mouseSound != soundNum)
    33.     {
    34.       mouseSound = soundNum;
    35.       mSound.play();
    36.     }
    37.   }
    38.   else
    39.   {
    40.     fill(100);
    41.     if (mouseSound == soundNum)
    42.     {
    43.       mouseSound = -1;
    44.     }
    45.   }
    46.     
    47.   text(words, xPos, yPos);
    48. }

    49. void precacheSound ()
    50. {
    51.   mSoundLoader = new Minim(this);
    52.   
    53.   mSound = mSoundLoader.loadFile("highlight.wav");
    54. }


    With this code, whenever I highlight a text option, it brightens up (via the fill()). However, I cannot get sound to play. It sometimes play when it's supposed to, and it sometimes doesn't. What am I doing wrong?

    Replies(6)

    The code above is not your complete code...
    We can't see fully what you have going on.

    I can see that you are using Minim... but without being able to test the code, there is little that we can do to help.
    Whoops, sorry. I posted this late at night, so I forgot a lot of things. I've updated the first post with everything.
    It still doesn't work...
    For example: You don't declare mSound anywhere...
    It works now (with an added sound file)...

    It works for me...
    It doesn't stop playing when you stop hovering the mouse over it, though.

    It might have something to do with your sound file...
    I'm using one of the MP3 files that came with Windows.

    If not that, maybe the sound on your computer...
    The sound file I was using was very very small. Using a longer sound worked.

    Thanks for your help!