示例#1
1
 public static Audio playWav(String wavFile, boolean loop) {
   try {
     AudioLoader.update(); // JIC
     Audio wav = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream(wavFile));
     sounds.add(wav);
     wav.playAsMusic(1.0f, 1.0f, loop);
     return wav;
   } catch (IOException e) {
     e.printStackTrace();
   }
   return null;
 }
示例#2
1
  /** Initialise resources */
  public void init() {
    try {
      wavEffect =
          AudioLoader.getAudio(
              "WAV",
              ResourceLoader.getResourceAsStream("com/etk2000/SpaceGame/Music/MainMenuMusic.wav"));
      // @param: something, something, loop
      wavEffect.playAsMusic(1.0f, 1.0f, true);
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }

    /*
     * try {
     * // you can play oggs by loading the complete thing into
     * // a sound
     * oggEffect = AudioLoader.getAudio("OGG",
     * ResourceLoader.getResourceAsStream("testdata/restart.ogg"));
     *
     * // or setting up a stream to read from. Note that the argument becomes
     * // a URL here so it can be reopened when the stream is complete. Probably
     * // should have reset the stream by thats not how the original stuff worked
     * oggStream = AudioLoader.getStreamingAudio("OGG",
     * ResourceLoader.getResource("testdata/bongos.ogg"));
     *
     * // can load mods (XM, MOD) using ibxm which is then played through OpenAL. MODs
     * // are always streamed based on the way IBXM works
     * modStream = AudioLoader.getStreamingAudio("MOD",
     * ResourceLoader.getResource("testdata/SMB-X.XM"));
     *
     * // playing as music uses that reserved source to play the sound. The first
     * // two arguments are pitch and gain, the boolean is whether to loop the content
     * modStream.playAsMusic(1.0f, 1.0f, true);
     *
     * // you can play aifs by loading the complete thing into
     * // a sound
     * aifEffect = AudioLoader.getAudio("AIF",
     * ResourceLoader.getResourceAsStream("testdata/burp.aif"));
     *
     * // you can play wavs by loading the complete thing into
     * // a sound
     * wavEffect = AudioLoader.getAudio("WAV",
     * ResourceLoader.getResourceAsStream("testdata/cbrown01.wav"));
     * } catch (Exception e) {
     * e.printStackTrace();
     * }
     */
  }
示例#3
0
  /** Game loop update */
  public void update() {
    while (Keyboard.next()) {
      if (Keyboard.getEventKeyState()) {
        if (Keyboard.getEventKey() == Keyboard.KEY_Q) {
          // play as a one off sound effect
          oggEffect.playAsSoundEffect(1.0f, 1.0f, false);
        }
        if (Keyboard.getEventKey() == Keyboard.KEY_W) {
          // replace the music thats curretly playing with
          // the ogg
          oggStream.playAsMusic(1.0f, 1.0f, true);
        }
        if (Keyboard.getEventKey() == Keyboard.KEY_E) {
          // replace the music thats curretly playing with
          // the mod
          modStream.playAsMusic(1.0f, 1.0f, true);
        }
        if (Keyboard.getEventKey() == Keyboard.KEY_R) {
          // play as a one off sound effect
          aifEffect.playAsSoundEffect(1.0f, 1.0f, false);
        }
        if (Keyboard.getEventKey() == Keyboard.KEY_T) {
          // play as a one off sound effect
          wavEffect.playAsSoundEffect(1.0f, 1.0f, false);
        }
      }
    }

    // polling is required to allow streaming to get a chance to
    // queue buffers.
    SoundStore.get().poll(0);
  }
示例#4
0
  public void update(int delta) {
    if (enabled) {
      if (musicPlaying == null) {
        musicDelay -= delta;

        if (musicDelay <= 0) {
          musicPlaying = music.get((int) (Math.random() * music.size()));
          musicPlaying.playAsMusic(1.0f, 1.0f, false);
          soundStore.setSoundVolume(0.5f);
        }
      } else if (!soundStore.isMusicPlaying()) {
        musicPlaying.stop();
        musicDelay = (int) (Math.random() * 90000) + 30000;
        musicPlaying = null;
        soundStore.setSoundVolume(0.75f);
      }

      if (ambientMusicPlaying == null) {
        ambientMusicDelay -= delta;

        if (ambientMusicDelay <= 0) {
          ambientMusicPlaying = ambientMusic.get((int) (Math.random() * ambientMusic.size()));
          ambientMusicPlaying.playAsSoundEffect(1.0f, (float) Math.random() * 0.2f + 1f, false);
        }
      } else if (!ambientMusicPlaying.isPlaying()) {
        ambientMusicPlaying.stop();
        ambientMusicDelay = (int) (Math.random() * 6000) + 1000;
        ambientMusicPlaying = null;
      }

      if (ambientNoisePlaying[0] == null) {
        ambientNoiseDelay[0] -= delta;

        if (ambientNoiseDelay[0] <= 0) {
          ambientNoisePlaying[0] = ambientNoise.get((int) (Math.random() * ambientNoise.size()));
          ambientNoisePlaying[0].playAsSoundEffect(1.0f, (float) Math.random() * 0.2f + 1f, false);
        }
      } else if (!ambientNoisePlaying[0].isPlaying()) {
        ambientNoisePlaying[0].stop();
        ambientNoiseDelay[0] = (int) (Math.random() * 16000) + 1000;
        ambientNoisePlaying[0] = null;
      }

      if (ambientNoisePlaying[1] == null) {
        ambientNoiseDelay[1] -= delta;

        if (ambientNoiseDelay[1] <= 0) {
          ambientNoisePlaying[1] = ambientNoise.get((int) (Math.random() * ambientNoise.size()));
          ambientNoisePlaying[1].playAsSoundEffect(1.0f, (float) Math.random() * 0.2f + 1f, false);
        }
      } else if (!ambientNoisePlaying[1].isPlaying()) {
        ambientNoisePlaying[1].stop();
        ambientNoiseDelay[1] = (int) (Math.random() * 16000) + 1000;
        ambientNoisePlaying[1] = null;
      }

      soundStore.poll(delta);
    }
  }
示例#5
0
 public static void playMusic(String name) {
   try {
     Audio song;
     song =
         AudioLoader.getAudio(
             "WAV",
             ResourceLoader.getResourceAsStream(
                 "resources" + Common.sep + "music" + Common.sep + name + ".wav"));
     song.playAsMusic(1.0f, 1.0f, true);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }