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

2015/12/3

Please help me buid my MP3 Player.

steezyjapaneezy steezyjapaneezy

2015/12/3

#
Im making a simple MP3 player with play/pause button that includes 5 songs with 5 images. Here is the code I have so far, which Im not able to compile. It says "cannot find symbol - class Stop". What code am I missing? Any help is appreciated.
import greenfoot.*;

/**
 * Write a description of class Jukebox here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class JukeBox extends World
{
    private String[] buttons = {"A", "S", "D", "F", "G"};
    private String[] buttonImage = {"What Do You Mean.jpg","Writing's On the Wall.jpg","Rude.jpg","Lean On.jpg","Hello.jpg"};
    private String[] buttonSongs = {"Hello.mp3", "Rude.mp3", "What Do You Mean.mp3", "Writing's On the Wall.mp3","Lean On.mp3"};
    private int [] buttonType = {1,1,1,1,1};
 

    public JukeBox()
    {    
        super(600, 400, 1); 
        makeButtons();
    }
 
    private void makeButtons()
    {
        for(int i = 0; i < buttons.length; i++)
        {
            Button button = new Button ( buttons[i], buttonSongs[i]+ "",buttonImage[i] + "", buttonType[i]);
            addObject(button, i*63 + 50, 140);
            addObject(button, i,160);
            Stop stop = new Stop();
            addObject(stop, 100, 350);
            Play play = new Play();
            addObject(play, 180, 350);
         
        }
    }
 
}
steezyjapaneezy steezyjapaneezy

2015/12/3

#
Heres the code for my actor class 'Button'
import greenfoot.*;

/**
 * Write a description of class button here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */

public class Button extends Actor
{
    private String buttonName;
    private String sound;
    private int typeOfButton;
    private String buttonImage;
    private GreenfootSound gfs;
    private boolean isPlaying;
     
    public Button(String buttons, String soundFile, String image, int buttonType)
    {
        buttonName = buttons;
        sound = soundFile;
        buttonImage = image;
        typeOfButton = buttonType; 
        gfs = new GreenfootSound(sound); 
    }
}
danpost danpost

2015/12/3

#
Apparently, you do not have a 'Stop' class. You may find that you do not have a 'Play' class, either. These two classes should both be subclasses of the Actor class.
steezyjapaneezy steezyjapaneezy

2015/12/4

#
I totally forgot about that, thanks for the help. Ive now created both actors, but they don't seem to work properly. Are there any simple codes to make both stop/play buttons to work?
danpost danpost

2015/12/5

#
Well, I can say that having the field 'isPlaying' in the Button class is not very wise. You want more control over what is playing so that only one is playing at a time and the best way to handle that is to keep a reference to the last button pressed in the world class with an indicator of the active state of the jukebox thee also. You may want to look over my Value Display Tutorial scenario and make use of a SimpleActor class instead of creating all the classes you have for the buttons.
You need to login to post a reply.