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

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

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

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: 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: 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: bladecoder/bladecoder-adventure-engine

public void resume() {
  if (voice != null && isPaused) {
    voice.play();
    isPaused = false;
  }
}
origin: bladecoder/bladecoder-adventure-engine

public void resumeMusic() {
  if (music != null && isPaused) {
    music.play();
    isPaused = false;
  }
}
origin: 00-Evan/shattered-pixel-dungeon-gdx

public void resume() {
  if (player != null) {
    player.play();
  }
}

origin: com.harium.etyl/etyl-gdx

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

public void play() {
  if (currentMusic != null && !currentMusic.isPlaying()) {
    currentMusic.play();
  }
}
origin: yichen0831/Bomberman_libGdx

public void playMusic() {
  if (currentMusic.isEmpty()) {
    return;
  }
  Music music = assetManager.get(musicPath + currentMusic, Music.class);
  music.play();
}
origin: Catacomb-Snatch/Catacomb-Snatch

@Override
public void resumeBackgroundMusic() {
  paused = false;
  if (backgroundPlaying >= 0) backgroundMusicList.get(backgroundPlaying).play();
  if (TitleIsPlaying) {
    getMusic(Sounds.TITLE_THEME).play();
  }
  if (TheEndIsPlaying) {
    getMusic(Sounds.END_THEME).play();
  }
}
origin: dingjibang/GDX-RPG

/**播放一个音乐,如果正在播的就是这首音乐,则重新播放*/
public MusicProxy play(String path) {
  MusicProxy proxy = null;
  if(manager.containsKey(path)){
    proxy = manager.get(path);
  }else{
    proxy = new MusicProxy(Gdx.audio.newMusic(Gdx.files.internal(path)));
    manager.put(path, proxy);
  }
  
  proxy.music.play();
  
  return proxy;
}
 
origin: kbz/SIFTrain

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

public void resume() {
  var3dListener.onIOSResume();
  if (isMusic != false && music != null)
    music.play();
  if (stage != null && isLoading)
    stage.resume();
}
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();
  }
}
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: bladecoder/bladecoder-adventure-engine

  @Override
  public void run() {
    music = Gdx.audio.newMusic(EngineAssetManager.getInstance().getAsset(style.musicFile));
    music.setLooping(true);
    music.play();
  }
}.start();
origin: bladecoder/bladecoder-adventure-engine

  @Override
  public void run() {
    music = Gdx.audio.newMusic(EngineAssetManager.getInstance().getAsset(sound));
    
    try {
      music.play();
    } catch(Exception e) {
      // sometimes the play method fails on desktop.
      EngineLogger.error("Error Playing music: " + s, e);
    }
  }
}.start();    
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: BrentAureli/FlappyDemo

@Override
public void create () {
  batch = new SpriteBatch();
  gsm = new GameStateManager();
  music = Gdx.audio.newMusic(Gdx.files.internal("music.mp3"));
  music.setLooping(true);
  music.setVolume(0.1f);
  music.play();
  Gdx.gl.glClearColor(1, 0, 0, 1);
  gsm.push(new MenuState(gsm));
}
com.badlogic.gdx.audioMusicplay

Javadoc

Starts the play back of the music stream. In case the stream was paused this will resume the play back. In case the music stream is finished playing this will restart the play back.

Popular methods of Music

  • 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

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
  • 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