Better is to create and keep a reference to a GreenfootSound object which you can control. With that, however, you have no control over it - it will play until completed (unless you close the project outright). GreenfootSound song new GreenfootSound ( 'song. But I dont know so much about Greenfoots SoundBuffers or what ever throws the Exception. But what makes me suprise: sometimes the sounds work like I want them to, but also sometimes they dont. You could probably eliminate either the 'soundFiles' or the 'songNames' array and use the same data for both creating the sound objects and displaying their names. The simplest way is to use aySound ( / string filename of music file / ). I got the sounds from YouTube (free YouTube to MP3 converter). Then you can start and stop the sound like this: sound.start () //start playing the sound sound.stop () //stop playing the sound ayLoop () //plays the sound over and over again //also you can use any other mehtod from the GreenfootSound class AceticAcid. The folder your scenario is in bears the name of your. You should create this sound as a global one (at the top of your code). That is where you paste the sound files for that project. Find the sounds folder and open it (it should be there and it should be empty). It seems a bit redundant to have two arrays with exactly the same data. Find the folder for the project you are working on and open it. But, the above should get your fields (which I renamed to more properly fit what they represent) and their references set up properly. I am quite sure that things will need to be tended to there as well. This also does not presume that the rest of the class is fine and correct. If you have ever found adding sound into Greenfoot difficult then this short video will give you the confidence you need. I presumes that your sound files are ".mp3" files - if not, you need to make the necessary correction. If(!selected & Greenfoot.mouseClicked(this)) This shows the adjustments to the beginning of your class. First you create a new sound like this: GreenfootSound sound new GreenfootSound ('filename') // the filename is the same as the one you would use in the playSound method You should create this sound as a global one (at the top of your code). Public PlayMusicButton(String soundFiles, String songNames, Color colors) If you want the sound to stop you have to use the class GreenfootSound. Public class PlayMusicButton extends Actor First, use the most recent version of Greenfoot (2.2.1), if youre not already.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |