Hi guys!
I want to read out, which sounds are in the 'sound'- folder...
In Greenfoot it works fine, but when I try out the exportet version, it always stops.
Can someone help me, please?
Here's the source code:
import greenfoot.*; import java.io.*; public class Music { private static GreenfootSound Music; private static String ActualMusic; private static int ActualMusicNumber; public static final void stopMusic() { if(Music!=null && Music.isPlaying()) Music.stop(); } public static final void playMusic(String SoundName) { if(Music!=null && Music.isPlaying()) Music.stop(); ActualMusic=SoundName; Music = new GreenfootSound(SoundName); Music.play(); } public static final void playNextMusic() { File File_Music = new File("sounds"); String[] Files = File_Music.list(); if(Files.length==0) return; ActualMusicNumber = (ActualMusicNumber+1)%Files.length; playMusic(Files[ActualMusicNumber]); } public static final void playMusicBefore() { File File_Music = new File("sounds"); String[] Files = File_Music.list(); if(Files.length==0) return; ActualMusicNumber--; if(ActualMusicNumber<0) ActualMusicNumber = Files.length-1; playMusic(Files[ActualMusicNumber]); } public static final void playMusic() { File File_Music = new File("sounds"); String[] Files = File_Music.list(); if(Files.length==0) return; ActualMusicNumber = Greenfoot.getRandomNumber(Files.length)%Files.length; playMusic(Files[ActualMusicNumber]); } }