0

I am trying to create a simple mp3 player in green foot and use buttons to control the volume. I have some code that I think should be working but it isnt. Im not sure what the problem is. I am trying to increase the volume bu one when the up button is pushed and decrease the volume by 1 when the down button is pushed I am fairly new to programming so any help would be great. Thanks!

    public class Play extends Actor
{
public GreenfootSound sound = new GreenfootSound("AdventureOfaLifetime.mp3");
private boolean off = true;
int currentVolume = sound.getVolume();

Up volumeUp;
Down volumeDown;

/**
 * Act - do whatever the Play wants to do. This method is called whenever
 * the 'Act' or 'Run' button gets pressed in the environment.
 */
public void act() 
{    
    if (Greenfoot.mouseClicked(this) && off)
    {
        setImage("Pause.png");
        sound.play();
        off = false;            
    }
    else if(Greenfoot.mouseClicked(this) && !off)
    {
        setImage("Play.png");
        sound.pause();
        off = true;
    }    

    if(volumeUp.clicked)
    {
        if(currentVolume < 100)
        {
            currentVolume = currentVolume + 1;
            sound.setVolume(currentVolume);
        }
    }

    if(volumeDown.clicked)
    {
        if(currentVolume > 0)
        {
            currentVolume = currentVolume - 1;
            sound.setVolume(currentVolume);
        }
    }
}

 public class Down extends Play
{
static boolean clicked = false;

/**
 * Act - do whatever the Down wants to do. This method is called whenever
 * the 'Act' or 'Run' button gets pressed in the environment.
 */
public void act() 
{
    if (Greenfoot.mouseClicked(this))
    {
        clicked = true;
    }
    else
    {
        clicked = false;
    }        
}     


public class Up extends Play
{
static boolean clicked = false;

/**
 * Act - do whatever the Up wants to do. This method is called whenever
 * the 'Act' or 'Run' button gets pressed in the environment.
 */
public void act() 
{
    if (Greenfoot.mouseClicked(this))
    {
        clicked = true;
    }
    else
    {
        clicked = false;
    }  
}    
tim_weaver
  • 21
  • 7

1 Answers1

0

I got something to work. I just set currentVolume equal to 50 then changed my if statement to currentVolume += 1;and currentVolume -= 1;. Probably isn't the best solution but at least its working.

tim_weaver
  • 21
  • 7