congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
Music
Code IndexAdd Tabnine to your IDE (free)

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

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

origin: libgdx/libgdx

@Override
public void render () {
  currentPosition = music.getPosition();
  Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  batch.begin();
  batch.draw(buttons, 0, 0);
  font.draw(batch, (int)currentPosition / 60 + ":" + (int)currentPosition % 60, 365, 35);
  batch.end();
  sliderUpdating = true;
  slider.setValue((currentPosition / songDuration) * 100f);
  sliderUpdating = false;
  stage.act();
  stage.draw();
  if (Gdx.input.justTouched()) {
    if (Gdx.input.getY() > Gdx.graphics.getHeight() - 64) {
      if (Gdx.input.getX() < 64) {
        music.play();
      }
      if (Gdx.input.getX() > 64 && Gdx.input.getX() < 128) {
        music.stop();
      }
      if (Gdx.input.getX() > 128 && Gdx.input.getX() < 192) {
        music.pause();
      }
    }
  }
}
origin: libgdx/libgdx

void setSong (Song song) {
  if (music != null) {
    music.dispose();
  }
  switch (song) {
  default:
  case MP3:
    music = Gdx.audio.newMusic(Gdx.files.internal("data/8.12.mp3"));
    songDuration = 183;
    break;
  case OGG:
    music = Gdx.audio.newMusic(Gdx.files.internal("data/cloudconnected.ogg"));
    songDuration = 22;
    break;
  case WAV:
    music = Gdx.audio.newMusic(Gdx.files.internal("data/8.12.loop.wav"));
    songDuration = 4;
    break;
  }
  music.setLooping(btLoop.isChecked());
  music.play();
}
origin: lycying/c2d-engine

private void playMusic(Music music,boolean loop){
  if(!music.isPlaying()){
    music.setVolume(musicVolume);
    music.setLooping(true);
    music.play();
  }
  
}
 
origin: kbz/SIFTrain

private void initMusic(Music mus) {
  mus.setLooping(true);
  mus.setVolume(0.0f);
  mus.play();
}
origin: kbz/SIFTrain

private void playMusicOnDemand() {
  if (!world.started) {
    world.started = true;
    if (hasMusic) {
      theSong.setLooping(false);
      theSong.setOnCompletionListener(this);
      theSong.setVolume(GlobalConfiguration.songVolume / 100f);
    }
  } else {
    if (world.paused) {
      world.paused = false;
      if (hasMusic) {
        theSong.setPosition(lastmtime);
        time = lastmtime + world.delay;
        theSong.play();
      }
    }
  }
}
origin: langurmonkey/gaiasky

private void playIndex(int i) {
  FileHandle f = musicFiles.get(i);
  if (currentMusic != null) {
    if (currentMusic.isPlaying()) {
      currentMusic.stop();
    }
    currentMusic.dispose();
  }
  try {
    currentMusic = Gdx.audio.newMusic(f);
    currentMusic.setVolume(volume);
    currentMusic.setOnCompletionListener(new OnCompletionListener() {
      @Override
      public void onCompletion(Music music) {
        playNextMusic();
      }
    });
    currentMusic.play();
    EventManager.instance.post(Events.MUSIC_TRACK_INFO, musicFiles.get(i).name());
    logger.info(I18n.bundle.format("gui.music.playing", musicFiles.get(i).name()));
  } catch (Exception e) {
    logger.error(e);
  }
}
origin: 00-Evan/shattered-pixel-dungeon-gdx

public void stop() {
  if (player != null) {
    player.stop();
    player.dispose();
    player = null;
  }
}

origin: Mknsri/Drunk-Toss

public TitleScreen() {
  if (DrunkToss.prefs.getBoolean("music") == false) {
    SoundLib.muteMusic = true;
    SoundLib.muteMusic();
  }
  SoundLib.menuMusic.play();
  SoundLib.menuMusic.setLooping(true);
}
 
origin: Catacomb-Snatch/Catacomb-Snatch

@Override
public void stopBackgroundMusic() {
  if (backgroundPlaying < 0) return;
  for (Music m : backgroundMusicList) {
    if (m.isPlaying()) m.stop();
  }
  backgroundPlaying = -1;
  backgroundIsPlaying = false;
}
origin: kbz/SIFTrain

private void disposeOf(Music mus) {
  if(mus == null)
    return;;
  if(mus.isPlaying())
    mus.stop();
  mus.dispose();
}
origin: bladecoder/bladecoder-adventure-engine

public void pause() {
  if (voice != null && voice.isPlaying()) {
    voice.pause();
    isPaused = true;
  }
}
origin: kbz/SIFTrain

resetMarks();
if (hasMusic) {
  theSong.pause();
  theSong.setPosition(aPosition);
  theSong.play();
  lastmtime = theSong.getPosition();
  time = lastmtime + world.delay;
  timeSyncAcc = 0;
music.dispose();
origin: libgdx/libgdx

@Override
public void create () {
  // copy an internal mp3 to the external storage
  FileHandle src = Gdx.files.internal("data/8.12.mp3");
  FileHandle dst = Gdx.files.external("8.12.mp3");
  src.copyTo(dst);
  // create a music instance and start playback
  Music music = Gdx.audio.newMusic(dst);
  music.play();
}
origin: dsaltares/libgdx-cookbook

void playSong(int songIdx) {
  Music song = songs.get(currentSongIdx);
  song.setOnCompletionListener(null);
  song.stop();
  
  currentSongIdx = songIdx;
  song = songs.get(currentSongIdx);
  song.play();
  song.setVolume(volume);
  song.setOnCompletionListener(listener);
}

origin: Var3D/var3dframe

/**
 * 播放音乐
 */
public void playMusic(String soundName) {
  if (music != null)
    music.stop();
  if (isMusic == false)
    return;
  if (assets.isLoaded(soundName, Music.class) == true) {
    music = assets.get(soundName, Music.class);
    music.setLooping(true);
    music.play();
  } else {
    assets.load(soundName, Music.class);
    assets.finishLoading();
    music = assets.get(soundName, Music.class);
    music.setLooping(true);
    music.play();
  }
}
origin: kbz/SIFTrain

theSong.pause();
theSong.setPosition(newAPosition);
theSong.setVolume(GlobalConfiguration.songVolume / 100f);
theSong.play();
origin: com.harium.etyl/etyl-gdx

public void play() {
  if (!loaded) {
    playOnLoad = true;
  }
  if (music == null || music.isPlaying()) {
    return;
  }
  music.play();
}
origin: moribitotech/MTX

private void clearCurrentMusic() {
  if (currentMusic != null) {
    currentMusic.stop();
    currentMusic = null;
  }
}
origin: org.mini2Dx/mini2Dx-core

private void fadeInNextTrack() {
  float trackTargetVolume = MathUtils.clamp(((cursor - crossfadeTime) / crossfadeDuration), 0f,
      targetVolume);
  nextTrack.setVolume(trackTargetVolume);
  if (!nextTrack.isPlaying() && playing) {
    nextTrack.play();
  }
}
origin: langurmonkey/gaiasky

public void playPauseToggle() {
  if (currentMusic != null) {
    if (currentMusic.isPlaying()) {
      currentMusic.pause();
    } else {
      currentMusic.play();
    }
  } else {
    start();
  }
}
com.badlogic.gdx.audioMusic

Javadoc

A Music instance represents a streamed audio file. The interface supports pausing, resuming and so on. When you are done with using the Music instance you have to dispose it via the #dispose() method.

Music instances are created via Audio#newMusic(FileHandle).

Music instances are automatically paused and resumed when an Application is paused or resumed. See ApplicationListener.

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

Most used methods

  • play
    Starts the play back of the music stream. In case the stream was paused this will resume the play ba
  • stop
    Stops a playing or paused Music instance. Next time play() is invoked the Music will start from the
  • isPlaying
  • setLooping
    Sets whether the music stream is looping. This can be called at any time, whether the stream is play
  • dispose
    Needs to be called when the Music is no longer needed.
  • setVolume
    Sets the volume of this music stream. The volume must be given in the range [0,1] with 0 being silen
  • pause
    Pauses the play back. If the music stream has not been started yet or has finished playing a call to
  • getPosition
    Returns the playback position in seconds.
  • setPosition
    Set the playback position in seconds.
  • setOnCompletionListener
    Register a callback to be invoked when the end of a music stream has been reached during playback.
  • getVolume
  • getVolume

Popular in Java

  • Start an intent from android
  • getExternalFilesDir (Context)
  • compareTo (BigDecimal)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • BufferedReader (java.io)
    Wraps an existing Reader and buffers the input. Expensive interaction with the underlying reader is
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • Base64 (org.apache.commons.codec.binary)
    Provides Base64 encoding and decoding as defined by RFC 2045.This class implements section 6.8. Base
  • Top PhpStorm plugins
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