예제 #1
0
 private void handleCache() {
   while (true) {
     for (Sound s : cache) {
       if (!s.isPlaying() && s.liveTime > 300) {
         cache.remove(s);
         continue;
       }
       s.liveTime++;
     }
     try {
       Thread.sleep(1000);
     } catch (InterruptedException e) {
       e.printStackTrace();
     }
   }
 }
예제 #2
0
 /**
  * Play a sound once
  *
  * @param name "object/sound(# for variation)"
  */
 public static void playSound(String name) {
   for (Sound s : cache) {
     if (s.name.equals(name)) {
       s.playSound();
       return;
     }
   }
   URL url = SoundHandler.class.getResource(path + name + ".mp3");
   if (url != null) {
     Media media = new Media(url.toExternalForm());
     Sound sound = new Sound(name, media);
     cache.add(sound);
     sound.playSound();
   } else {
     System.out.println("Unable to locate sound");
   }
 }