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

2017/4/24

Sound does not play

7oel 7oel

2017/4/24

#
I have a countdown, that makes a sound when it hits a number, it works fine, until i actually run the program where it comes up with an error message: java.lang.IllegalArgumentException: Could not open sound file: three.mp3 at greenfoot.sound.SoundExceptionHandler.handleIOException(SoundExceptionHandler.java:67) at greenfoot.sound.SoundFactory.createSound(SoundFactory.java:120) at greenfoot.Greenfoot.playSound(Greenfoot.java:163) at Countdown.Countdown3(Countdown.java:37) at Countdown.act(Countdown.java:29) at greenfoot.core.Simulation.actActor(Simulation.java:604) at greenfoot.core.Simulation.runOneLoop(Simulation.java:562) at greenfoot.core.Simulation.runContent(Simulation.java:221) at greenfoot.core.Simulation.run(Simulation.java:211) Caused by: java.io.FileNotFoundException: Could not find file: three.mp3 at greenfoot.util.GreenfootUtil.getURL(GreenfootUtil.java:554) at greenfoot.sound.SoundFactory.createSound(SoundFactory.java:99) ... 7 more This is my code:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Countdown here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Countdown extends Actor
{
    private GreenfootImage Countdown3 = new GreenfootImage("Countdown3.png");
    private GreenfootImage Countdown2 = new GreenfootImage("Countdown2.png");
    private GreenfootImage Countdown1 = new GreenfootImage("Countdown1.png");
    private GreenfootImage CountdownGo = new GreenfootImage("CountdownGo.png");
    private int countdowntimer;
    private boolean countDownFinished;
    public boolean isCountDownFinished() {
    return countDownFinished;
}
 

    /**
     * Act - do whatever the Countdown wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        
        Countdown3();
    }
    public void Countdown3()
    { 
        
        if(countdowntimer > 62)
        {
           Countdown2();
           Greenfoot.playSound("three.mp3");
           return;
        }
        else
        {
            countdowntimer++;
        }
        
    }
    public void Countdown2()
    {
        setImage(Countdown2);
        
        if(countdowntimer > 124)
        {
            Countdown1();
            Greenfoot.playSound("two.mp3");
            return;

        }
        else
        {
            countdowntimer++;
        }
        
    }
    public void Countdown1()
    {
        setImage(Countdown1);
        
        if(countdowntimer > 186)
        {
            CountdownGo();
            Greenfoot.playSound("one.mp3");
            countDownFinished = true;
            return;
        }
        else
        {
            countdowntimer++;
        }
        
    }
    public void CountdownGo()
    {
        setImage(CountdownGo);
        
        if(countdowntimer > 248)
        {
            Greenfoot.playSound("Go.mp3");
            World world;
            world=getWorld();
            world.removeObject(this);
            
            

        }
        else
        {
            countdowntimer++;
        }
        
    }
    
    
    
}
7oel 7oel

2017/4/24

#
Update, I have got all 3 in my greenfoot sounds folder with those exact names
danpost danpost

2017/4/24

#
I think you should simplify matters by ridding yourself of all the method calls. A simple class code might be something like this:
import greenfoot.*; 

public class Countdown extends Actor
{
    private GreenfootImage three = new GreenfootImage("Countdown3.png");
    private GreenfootImage two = new GreenfootImage("Countdown2.png");
    private GreenfootImage one = new GreenfootImage("Countdown1.png");
    private GreenfootImage go = new GreenfootImage("CountdownGo.png");
    private int countdowntimer;

    public void act()
    {
        countdowntimer++;
        if (countdowntimer == 62)
        {
            Greenfoot.playSound("three.mp3");
            setImage(two);
        }
        else if (countdowntimer == 124)
        {
            Greenfoot.playSound("two.mp3");
            setImage(one);
        }
        else if (countdowntimer == 186)
        {
            Greenfoot.playSound("one.mp3");
            setImage(go);
        }
        else if (countdowntimer == 248)
        {
            Greenfoot.playSound("go.mp3");
            getWorld().removeObject(this);
        }
    }
}
You can check to see if the Countdown object is in the world to verify completed count.
7oel 7oel

2017/4/24

#
danpost wrote...
I think you should simplify matters by ridding yourself of all the method calls. A simple class code might be something like this:
import greenfoot.*; 

public class Countdown extends Actor
{
    private GreenfootImage three = new GreenfootImage("Countdown3.png");
    private GreenfootImage two = new GreenfootImage("Countdown2.png");
    private GreenfootImage one = new GreenfootImage("Countdown1.png");
    private GreenfootImage go = new GreenfootImage("CountdownGo.png");
    private int countdowntimer;

    public void act()
    {
        countdowntimer++;
        if (countdowntimer == 62)
        {
            Greenfoot.playSound("three.mp3");
            setImage(two);
        }
        else if (countdowntimer == 124)
        {
            Greenfoot.playSound("two.mp3");
            setImage(one);
        }
        else if (countdowntimer == 186)
        {
            Greenfoot.playSound("one.mp3");
            setImage(go);
        }
        else if (countdowntimer == 248)
        {
            Greenfoot.playSound("go.mp3");
            getWorld().removeObject(this);
        }
    }
}
You can check to see if the Countdown object is in the world to verify completed count.
Ok so that works, but now. When it plays 3, it just says "th" and it misses two and then it says 1 and go prefectly
You need to login to post a reply.