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

2021/3/22

Stopping a sound in another world

TechNick TechNick

2021/3/22

#
Heyy! I´ve created a soundtrack for my first two worlds. Now that I wanna change to my third one I cant turn it off. Does anyone know how to help? Here´s my code:
GreenfootSound OnceInALifetime = new GreenfootSound("Once In A Lifetime.mp3");
 OnceInALifetime.playLoop();
When i tried
 OnceInALifetime.stop();
it didn´t work. I also tried:
greenfoot.GreenfootSound.stop();
but that didn´t work as well. Thanks for your help.
Risen Risen

2021/3/22

#
import greenfoot.*; 
public class MyWorld extends World {
GreenfootSound OnceInALifetime;
 public Menu() {    
  super(600, 400, 1);
  prepare();
 }
 private void prepare() { 
        OnceInALifetime = new GreenfootSound("Once In A Lifetime.mp3");
        OnceInALifetime.playLoop(); 
 }
 public void stopMusic() {
        OnceInALifetime.stop(); 
 }

}
In this case, you will not be able to get the object and do anything with it.
GreenfootSound OnceInALifetime = new GreenfootSound("Once In A Lifetime.mp3");
TechNick TechNick

2021/3/22

#
But when I execute the method stopMusic() it doesn´t stop. But thanks for the quick response.
Risen Risen

2021/3/22

#
TechNick wrote...
But when I execute the method stopMusic() it doesn´t stop. But thanks for the quick response.
Try restarting greenfoot.
TechNick TechNick

2021/3/22

#
Ahhh, now it´s working. Thanks a lot!!!
You need to login to post a reply.