Methapolis  0.27
 All Classes Namespaces Files Functions Variables Enumerator
Sound.java
Go to the documentation of this file.
1 // This file is part of MicropolisJ.
2 // Copyright (C) 2013 Jason Long
3 // Portions Copyright (C) 1989-2007 Electronic Arts Inc.
4 //
5 // MicropolisJ is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU GPLv3, with additional terms.
7 // See the README file, included in this distribution, for details.
8 
9 package micropolisj.engine;
10 
11 import java.net.URL;
12 
13 import javax.sound.sampled.AudioSystem;
14 import javax.sound.sampled.Clip;
15 
21 public enum Sound
22 {
23  EXPLOSION_LOW ("explosion-low"),
24  EXPLOSION_HIGH("explosion-high"),
25  EXPLOSION_BOTH("explosion-low"),
26  UHUH ("bop"),
27  SORRY ("bop"),
28  BUILD ("layzone"),
29  BULLDOZE (null),
30  HONKHONK_LOW ("honkhonk-low"),
31  HONKHONK_MED ("honkhonk-med"),
32  HONKHONK_HIGH ("honkhonk-high"),
33  HONKHONK_HI ("honkhonk-hi"),
34  SIREN ("siren"),
35  HEAVYTRAFFIC ("heavytraffic"),
36  MONSTER ("zombie-roar-5"),
37  // CUSTOM
38  DUBSPLOSION ("dubsplosion"),
39  SPACESHIP_LAUNCH("missle_launch"),
40  BG_MUSIC ("methapolis");
41 
42  String wavName;
43 
44 
45  private Sound(String wavName) {
46  this.wavName = wavName;
47  }
48 
49  public URL getAudioFile() {
50  return getAudioFile("wav");
51  }
52 
57  public URL getAudioFile(String fileEnding) {
58  String n2 = "/sounds/" + wavName + "." + fileEnding;
59  URL u = Sound.class.getResource(n2);
60  return u;
61  }
62 
63  public static void playSound(Sound sound) {
64  playSound(sound, "wav");
65  }
66 
67  public static void playSound(Sound sound, String fileEnding) {
68  System.out.println("playing a sound");
69  URL afile = sound.getAudioFile(fileEnding);
70  if(afile == null) {
71  return;
72  }
73 
74  // System.out.println(afile);
75 
76  try {
77  Clip clip = AudioSystem.getClip();
78  clip.open(AudioSystem.getAudioInputStream(afile));
79  clip.start();
80  }
81  catch(Exception e) {
82  e.printStackTrace(System.err);
83  }
84  }
85 
86  public String getWavName() {
87  return wavName;
88  }
89 }