Tabnine Logo
Sound
Code IndexAdd Tabnine to your IDE (free)

How to use
Sound
in
com.badlogic.gdx.audio

Best Java code snippets using com.badlogic.gdx.audio.Sound (Showing top 20 results out of 315)

origin: libgdx/libgdx

@Override
public void create () {
  Gdx.audio.newSound(Gdx.files.internal("data/tic.ogg")).play();
}
origin: libgdx/libgdx

  public void clicked (InputEvent event, float x, float y) {
    sound.stop(soundId);
  }
});
origin: libgdx/libgdx

  @Override
  public void dispose () {
    ui.dispose();
    skin.dispose();
    sound.dispose();
  }
}
origin: libgdx/libgdx

  public void clicked (InputEvent event, float x, float y) {
    soundId = sound.play(volume.getValue());
    sound.setPitch(soundId, pitch.getValue());
    sound.setPan(soundId, pan.getValue(), volume.getValue());
  }
});
origin: net.mostlyoriginal.artemis-odb/contrib-jam

public void playSfx(String name) {
  if (sfxVolume > 0) {
    Sound sfx = getSfx(name);
    if (sfx != null) {
      sfx.stop();
      sfx.play(sfxVolume, MathUtils.random(1f, 1.04f), 0);
    }
  }
}
origin: bladecoder/bladecoder-adventure-engine

  @Override
  public void changed(ChangeEvent event, Actor actor) {
    SoundDesc selected = list.getSelected();
    if (playingSound != null) {
      playingSound.stop();
      playingSound.dispose();
      playingSound = null;
    }
    playingSound = Gdx.audio.newSound(
        new FileHandle(Ctx.project.getAssetPath() + Project.SOUND_PATH + "/" + selected.getFilename()));
    playingSound.play(selected.getVolume(), 1, selected.getPan());
    Timer.schedule(new Task() {
      @Override
      public void run() {
        if (playingSound != null) {
          playingSound.stop();
          playingSound.dispose();
          playingSound = null;
        }
      }
    }, 5);
  }
});
origin: dsaltares/libgdx-cookbook

sound.stop();
sound.pause();
sound.resume();
sound.play();
Gdx.app.log("SoundEffectSample", "Playing sound");
origin: dsaltares/libgdx-cookbook

idle.stop();
soundId = engine.play();
engine.setLooping(soundId, true);
engine.stop();
soundId = idle.play();
idle.setLooping(soundId, true);
engine.setPitch(soundId, pitch);
origin: bladecoder/bladecoder-adventure-engine

  @Override
  public void changed(ChangeEvent event, Actor actor) {
    if (s != null) {
      s.dispose();
      s = null;
    }
    if (filename.getText() != null && !filename.getText().isEmpty()) {
      s = Gdx.audio.newSound(
          new FileHandle(Ctx.project.getAssetPath() + Project.SOUND_PATH + "/" + filename.getText()));
      s.play(Float.parseFloat(volume.getText()), Float.parseFloat(pitch.getText()),
          Float.parseFloat(pan.getText()));
    }
  }
});
origin: jmrapp1/SpaceInvaders

public void playSound(String id, float volume) {
  Sound sound = getSound(id);
  if (sound != null) {
    long songId = sound.play();
    sound.setVolume(songId, volume);
  }
}
 
origin: bladecoder/bladecoder-adventure-engine

public void playSound(String id) {
  LoadedSound s = loadedSounds.get(id);
  if (s == null) {
    // Not loaded, load and add to the loaded list.
    SoundDesc sd = w.getSounds().get(id);
    if (sd != null) {
      addSoundToLoad(sd);
      s = loadedSounds.get(id);
      EngineLogger.debug("LOADING SOUND: " + s.desc.getId() + " - " + s.desc.getFilename());
      EngineAssetManager.getInstance().loadSound(s.desc.getFilename());
      EngineAssetManager.getInstance().finishLoading();
      s.sound = EngineAssetManager.getInstance().getSound(s.desc.getFilename());
    }
  }
  if (s != null && s.sound != null) {
    if (s.desc.getLoop())
      s.sound.loop(s.desc.getVolume() * VOLUME_MULTIPLIER, s.desc.getPitch(), s.desc.getPan());
    else
      s.sound.play(s.desc.getVolume() * VOLUME_MULTIPLIER, s.desc.getPitch(), s.desc.getPan());
    s.playing = true;
  } else {
    EngineLogger.error("Sound Not Found: " + id);
  }
}
origin: manuelbua/uracer-kotd

private void onBeginDrift () {
  if (driftId > -1) {
    drift.stop(driftId);
    driftId = drift.loop(0f);
    drift.setVolume(driftId, 0f);
  }
  doFadeIn = true;
  doFadeOut = false;
}
origin: Catacomb-Snatch/Catacomb-Snatch

@Override
public void shutdown() {
  Music music;
  // unloading Title music
  stopTitleMusic();
  music = getMusic(Sounds.TITLE_THEME);
  if (music != null) {
    music.dispose();
  }
  // unloading End music
  stopEndMusic();
  music = getMusic(Sounds.END_THEME);
  if (music != null) {
    music.dispose();
  }
  // unloading Background music
  stopBackgroundMusic();
  for (Music m : backgroundMusicList) {
    if (m.isPlaying()) m.stop();
    m.dispose();
  }
  // unloading sounds
  if (soundsMap.size > 0) {
    for (Sound s : soundsMap.values()) {
      s.stop();
      s.dispose();
    }
  }
}
origin: libgdx/libgdx

  public void changed (ChangeEvent event, Actor actor) {
    sound.setVolume(soundId, volume.getValue());
    volumeValue.setText("" + volume.getValue());
  }
});
origin: manuelbua/uracer-kotd

private void start () {
  if (started) {
    return;
  }
  started = true;
  driftId = loop(drift, 0f);
  drift.setPitch(driftId, pitchMin);
  drift.setVolume(driftId, 0f);
}
origin: Mknsri/Drunk-Toss

public void fightStart() {
  currentState = STATE.ENGAGED;
  fightID = SoundLib.fightSounds.loop(SoundLib.sVolume);
}
 
origin: jmrapp1/SpaceInvaders

public Sound loopSound(String id, float volume) {
  Sound sound = getSound(id);
  if (sound != null) {
    long songId = sound.loop();
    sound.setVolume(songId, volume);
  }
  return sound;
}
 
origin: bladecoder/bladecoder-adventure-engine

public void resume() {
  for (LoadedSound s : loadedSounds.values()) {
    if (s.playing && s.sound != null)
      s.sound.resume();
  }
}
origin: bladecoder/bladecoder-adventure-engine

public void pause() {
  for (LoadedSound s : loadedSounds.values()) {
    if (s.playing && s.sound != null)
      s.sound.pause();
  }
}
origin: DaanVanYperen/artemis-odb-contrib

public void playSfx(String name) {
  if (sfxVolume > 0) {
    Sound sfx = getSfx(name);
    if (sfx != null) {
      sfx.stop();
      sfx.play(sfxVolume, MathUtils.random(1f, 1.04f), 0);
    }
  }
}
com.badlogic.gdx.audioSound

Javadoc

A Sound is a short audio clip that can be played numerous times in parallel. It's completely loaded into memory so only load small audio files. Call the #dispose() method when you're done using the Sound.

Sound instances are created via a call to Audio#newSound(FileHandle).

Calling the #play() or #play(float) method will return a long which is an id to that instance of the sound. You can use this id to modify the playback of that sound instance.

Note: any values provided will not be clamped, it is the developer's responsibility to do so

Most used methods

  • play
    Plays the sound. If the sound is already playing, it will be played again, concurrently.
  • stop
    Stops the sound instance with the given id as returned by #play() or #play(float). If the sound is n
  • dispose
    Releases all the resources.
  • loop
    Plays the sound, looping. If the sound is already playing, it will be played again, concurrently. Yo
  • setVolume
    Changes the volume of the sound instance with the given id as returned by #play() or #play(float). I
  • pause
    Pauses the sound instance with the given id as returned by #play() or #play(float). If the sound is
  • resume
    Resumes the sound instance with the given id as returned by #play() or #play(float). If the sound is
  • setPitch
    Changes the pitch multiplier of the sound instance with the given id as returned by #play() or #play
  • setPan
    Sets the panning and volume of the sound instance with the given id as returned by #play() or #play(
  • setLooping
    Sets the sound instance with the given id to be looping. If the sound is no longer playing this has

Popular in Java

  • Reactive rest calls using spring rest template
  • notifyDataSetChanged (ArrayAdapter)
  • compareTo (BigDecimal)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • String (java.lang)
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • LinkedHashMap (java.util)
    LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations a
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now