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

2015/4/26

Can't insert background music into the world (file not found)

Allhard Allhard

2015/4/26

#
Hello, i got problem when inserting bg music to main menu world. greenfoot terminal keeps saying file not found. but im sure i already put the file in sounds folder inside scenario folder and the filenaming was right. Here's the directory: C:\Users\Personal\Documents\Adjojing\sounds (Adjodjing is the scenario name) Or maybe there's something wrong with my code? here's the code:
public void act()
    {
       Greenfoot.playSound("sandstorm.mp3");
    }
i've tried this code also but doesnt works either
public GreenfootSound bgMusic = new GreenfootSound("sandstorm.mp3"); public void started() { bgMusic.playLoop(); } public void stopped() { bgMusic.stop(); }
note: sandstorm is the bgMusic filename.
danpost danpost

2015/4/26

#
Allhard wrote...
note: sandstorm is the bgMusic filename.
Yes -- and it may be under the 'Adjodjing' directory (which is the name of your scenario. However, I do not see 'Greenfoot' in the filepath, which leads me to believe that you created another directory with the name of your scenario. The sound file needs to be copied into your 'Greenfoot/Adjodjing/sounds' directory (the 'sounds' folder that is located with the class files of your Adjodjing project).
Allhard Allhard

2015/4/26

#
danpost wrote...
Allhard wrote...
note: sandstorm is the bgMusic filename.
Yes -- and it may be under the 'Adjodjing' directory (which is the name of your scenario. However, I do not see 'Greenfoot' in the filepath, which leads me to believe that you created another directory with the name of your scenario. The sound file needs to be copied into your 'Greenfoot/Adjodjing/sounds' directory (the 'sounds' folder that is located with the class files of your Adjodjing project).
my bad, i've backup the scenario with a new name so it wont works lol. oh yea, can i ask another question? how do you stop di bgMusic when you're switching to another world class. I mean: the music started in World1 and still playing in World2 but when the World3 started, i want the bgMusic stop. here's what i code earlier that didnt worked (this is in World1):
public void act()
    {
        musicstart();
    }
    
    public GreenfootSound bgMusic = new GreenfootSound("sandstorm.mp3");
    
    public void musicstart()
    {
        bgMusic.playLoop();
    }
    public void musicstopped()
    {
        bgMusic.stop();
    }
and this is in an actor inside World 3:
{
            ((MainMenu) getWorld()).musicstopped();
}
or
MainMenu MainMenu = (MainMenu) getWorld();
            MainMenu.musicstopped();
danpost danpost

2015/4/26

#
Modify the 'bgMusic' field with the 'static' keyword and use 'World1.bgMusic.stop()' when needed
Allhard Allhard

2015/4/26

#
danpost wrote...
Modify the 'bgMusic' field with the 'static' keyword and use 'World1.bgMusic.stop()' when needed
how do you make it static? by changing the syntax from public to private in line 6, 8, and 12 perhaps? i've tried to use public static but compiler says bgMusic cant be referenced as a static. any idea?
danpost danpost

2015/4/26

#
Allhard wrote...
i've tried to use public static but compiler says bgMusic cant be referenced as a static. any idea?
You should show what you tried along with the code that references it -- particularly where the compiler points at..
azazeel azazeel

2015/4/27

#
may be you should not write this public void act() { musicstart(); } because, every act will play sound and..... if you are frustrated enough just give us the full project and let's fix it together
Allhard Allhard

2015/4/27

#
danpost wrote...
You should show what you tried along with the code that references it -- particularly where the compiler points at..
Well, i still have the same issues from yesterday. I want to start a bgMusic1 from World1 (MainMenu) and when the World2(selectstage) started the bgMusic1 still on. But if player click an actor (takemehome.class) that belongs to World2, the bgMusic1 stopped and the bgMusic2 appears along with World3(gamestart). here's the code of World1:
public void act()
    {
        musicstart();
    }
    private GreenfootSound bgMusic = new GreenfootSound("sandstorm.mp3");
    public boolean bgmp = true;
    public void musicstart()
    {
        bgMusic.playLoop();
    }
    public void musicstop()
    {
        ibgmp = false;
        {
            bgMusic.stop();
        }
    }
and here's the code of takemehome.class
public void act() 
    {
        if(Greenfoot.mouseClicked(this))
        {        
            ((MainMenu).getWorld().musicstop());
            PlaySong1 PlaySong1 = new PlaySong1();
            Greenfoot.setWorld(PlaySong1);
        }
    } 
Im currently trying it by using a boolean as a parameter to play&stop bgMusic but stucked at World-Actor relationship.
Allhard Allhard

2015/4/27

#
azazeel wrote...
may be you should not write this public void act() { musicstart(); } because, every act will play sound and..... if you are frustrated enough just give us the full project and let's fix it together
well, since the deadline is the next 24 hours..... where do we have to upload it sir?
azazeel azazeel

2015/4/27

#
just upload here on your scenario to greenfoot.org :) and we dont give guarantee, just try :)
danpost danpost

2015/4/27

#
In the MainMenu class, remove the 'bgmp' field and both the 'musicstart' and musicstop' methods; then change 'act' to 'started' and 'private GreenfootSound' to 'public static GreenfootSound'. Finally in the 'act' method of the takemehome class, change line 5 to:
MainMenu.bgMusic.stop();
You need to login to post a reply.