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

2022/10/23

Sound is not beeing played

N8TH1N6 N8TH1N6

2022/10/23

#
Hey I wanna add a background music when you are in the main menu but somehow it just wont play the sound. I added the file to the sounds folder and even tried it to play when an action is done but both didnt work
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class MainMenu here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class MainMenu extends World
{
    private static final GreenfootSound intro = new GreenfootSound("intro.wav");
    /**
     * Constructor for objects of class MainMenu.
     * 
     */
    public MainMenu()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1);
        intro.playLoop();
        addObject(new playButton(), 99, 111);
        addObject(new creditsButton(), 74, 383);
        
        prepare();
    }
    /**
     * Prepare the world for the start of the program.
     * That is: create the initial objects and add them to the world.
     */
    private void prepare()
    {
        logo logo = new logo();
        addObject(logo,113,37);
    }
    

}
best
danpost danpost

2022/10/23

#
N8TH1N6 wrote...
I wanna add a background music when you are in the main menu but somehow it just wont play the sound. I added the file to the sounds folder and even tried it to play when an action is done but both didnt work << Code Omitted >>
Try this:
import greenfoot.*;

public class MainMenu extends World
{
    private GreenfootSound intro = new GreenfootSound("intro.wav");
    
    public MainMenu()
    {
        super(600, 400, 1);
        addObject(new logo(), 113, 37);
    }
    
    public void started()
    {
        intro.playLoop();
        addObject(new playButton(), 99, 111);
        addObject(new creditsButton(), 74, 383);
    }
}
If still won't play, try changing the sound file to type "mp3".
N8TH1N6 N8TH1N6

2022/10/23

#
Hey, it still doesn't work, also with an mp3 is it maybe a problem with the sound file itself? It works outside of greenfoot
danpost danpost

2022/10/24

#
N8TH1N6 wrote...
it still doesn't work, also with an mp3 is it maybe a problem with the sound file itself? It works outside of greenfoot
When you tried mp3, did you adjust line 5 to point to that file?
N8TH1N6 N8TH1N6

2022/10/24

#
danpost wrote...
N8TH1N6 wrote...
it still doesn't work, also with an mp3 is it maybe a problem with the sound file itself? It works outside of greenfoot
When you tried mp3, did you adjust line 5 to point to that file?
yes, the music works at a different computer idk why it doesnt works on mein
You need to login to post a reply.