This site requires JavaScript, please enable it in your browser!
Greenfoot back
mandyg233
mandyg233 wrote ...

2014/5/20

Sound Not Working

1
2
mandyg233 mandyg233

2014/5/20

#
So basically the sound is a really short sound it only lasts about 3 seconds, but when I run it, the sound does not stop. This is my code: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.io.*; /** * Write a description of class Boat here. * * @author (your name) * @version (a version number or a date) */ public class Boat extends Actor { /** * Act - do whatever the Boat wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if (getX() >1185) { move(-5); } if (getX() == 1185) { Greenfoot.playSound("crack.mp3"); } } }
wabuilderman wabuilderman

2014/5/20

#
Where is crack.mp3 imported/inialized?
mandyg233 mandyg233

2014/5/20

#
It's in the sounds folder, is that what you mean?
wabuilderman wabuilderman

2014/5/20

#
no, I mean, you have to have it recognized by that class, you can't just have it go looking everywhere for some sound file
wabuilderman wabuilderman

2014/5/20

#
Also, why do you have io imported?
mandyg233 mandyg233

2014/5/20

#
Honestly I have no idea why I imported io, I looked on here earlier and their code worked with the io import. I guess I don't have it initialized.. how would I go about doing that?
mandyg233 mandyg233

2014/5/20

#
Right now it seems like it's looping
wabuilderman wabuilderman

2014/5/20

#
If it works, and it is looping, then you just need to scan the greenfoot Library, and find the method to stop it.
mandyg233 mandyg233

2014/5/20

#
Okay so I changed it to: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.io.*; /** * Write a description of class Boat here. * * @author (your name) * @version (a version number or a date) */ public class Boat extends Actor { private GreenfootSound soundSound = new GreenfootSound("crack.mp3"); /** * Act - do whatever the Boat wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if (getX() >1185) { move(-5); } if (getX() == 1185) { Greenfoot.delay(5); getWorld().addObject(new Label(), 400, 249); soundSound.play(); soundSound.stop(); } } } and now no sound plays at all
wabuilderman wabuilderman

2014/5/20

#
The sound IS playing, yet it is not. You are stoping it on the same frame you are playing it.
wabuilderman wabuilderman

2014/5/20

#
What you should do is have there be a pause, the length of the sound clip, and have it stop, only after that pause
mandyg233 mandyg233

2014/5/20

#
How do I get that to not happen? I tried a delay and it just kept looping
wabuilderman wabuilderman

2014/5/20

#
By the way, don't take my word on this, I have not memorized the methods in the Greenfoot library by heart.
mandyg233 mandyg233

2014/5/20

#
Not the pause from the GreenfootSound API though right? Because that would pause the sound right basically before it had even begun like the stop method
wabuilderman wabuilderman

2014/5/20

#
no, not that pause. I mean like greenfoot delay pause
There are more replies on the next page.
1
2