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

2013/2/14

Stoping the sound playing

Solringolt Solringolt

2013/2/14

#
I actually want to do a button on/off for music but i don't know how to stop around that is actually playing..
Gevater_Tod4711 Gevater_Tod4711

2013/2/14

#
If you start the music using Greenfoot.playSound(...) you can't stop the sound. To stop it or pause it you have to use the class GreenfootSound.
1
2
3
4
5
//instead of:
Greenfoot.playSound("sound.mp3");
//do this:
GreenfootSound sound = new GreenfootSound("sound.mp3");
sound.play();
Then you easily can stop or pause the sound.
1
2
sound.pause();//pauses the sound;
sound.stop();//stops the sound;
danpost danpost

2013/2/14

#
When using the Greenfoot class 'playSound' method, you do not have an object reference to the GreenfootSound object to control it. If you create a GreenfootSound object, you can use the GreenfootSound class methods to control the playing/stopping of the sound.
Solringolt Solringolt

2013/2/15

#
Thx a lot! It works now :D
You need to login to post a reply.