Example usage for com.badlogic.gdx.audio Music stop

List of usage examples for com.badlogic.gdx.audio Music stop

Introduction

In this page you can find the example usage for com.badlogic.gdx.audio Music stop.

Prototype

public void stop();

Source Link

Document

Stops a playing or paused Music instance.

Usage

From source file:com.forerunnergames.peril.client.ui.music.MusicController.java

License:Open Source License

private void stopMusicWithFadeOut(final Music music) {
    Timer.schedule(new Timer.Task() {
        @Override/*www. j  a v a2s . c  om*/
        public void run() {
            if (!music.isPlaying()) {
                cancel();
                log.trace("Stopping fading out music [{}] because it isn't playing anymore.", music);
                return;
            }

            final float currentVolume = music.getVolume();
            final float delta = masterVolume.getVolume() / MusicSettings.FADE_VOLUME_REPEAT_COUNT;
            final float newVolume = currentVolume - delta;

            log.trace("Fading out music [{}] from volume [{}] to volume [{}].", music, currentVolume,
                    newVolume);

            if (newVolume <= MusicSettings.MIN_VOLUME) {
                music.stop();
                cancel();
                log.trace("Done fading out & stopping music [{}].", music);
                return;
            }

            music.setVolume(newVolume);
        }
    }, 0.0f, MusicSettings.FADE_VOLUME_INTERVAL_SECONDS, MusicSettings.FADE_VOLUME_REPEAT_COUNT);
}

From source file:com.mangecailloux.pebble.audio.MusicManager.java

License:Apache License

/** Remove a {@link Music}. This will not unload the music. 
 * @param _key ID of the music instance.
 *//*from   ww  w.j a  va2  s . c  om*/
public void unregister(String _key) {
    Music music = musics.get(_key);
    if (music != null && music.isPlaying())
        music.stop();
    musics.remove(_key);
}

From source file:com.mangecailloux.pebble.audio.MusicManager.java

License:Apache License

/**
 * Stop the Music.//from w  ww. j  a  v  a2  s.  c o  m
 * @param _key ID of the music.
 */
public void stop(String _key) {
    Music music = get(_key);
    if (music != null && music.isPlaying()) {
        music.stop();
    }
}

From source file:com.paulogaspar.ninja.screens.Credits.java

public Credits(MyGame game, Ninja player, Texture master_texture[], Texture item_texture[], Texture cannonD,
        Texture cannonR, Texture cannonL, Texture cannonBall, Texture ninja_star, BitmapFont font_32,
        BitmapFont font_16, Music m, Sound bomb_sound, Sound item_sound) {
    batch = new SpriteBatch();
    camera = new OrthographicCamera();
    camera.setToOrtho(false, 800, 600);//w  w w . j  a  v  a 2s .co m
    this.player = player;
    this.game = game;
    this.ninja_star = ninja_star;
    this.cannonD = cannonD;
    this.cannonL = cannonL;
    this.cannonR = cannonR;
    this.cannonBall = cannonBall;
    this.master_texture = master_texture;
    this.item_texture = item_texture;
    this.font_32 = font_32;
    this.font_16 = font_16;
    this.bomb_sound = bomb_sound;
    this.item_sound = item_sound;

    while (m.isPlaying()) {
        m.stop();
    }
    m.dispose();

    try {
        main_theme = Gdx.audio.newMusic(Gdx.files.internal("Music/end.mp3"));
    } catch (Exception e) {
    }

    while (!main_theme.isPlaying()) {
        try {
            main_theme.play();
            main_theme.setVolume(player.master_volume);
            main_theme.setLooping(true);
        } catch (Exception e) {
            main_theme.stop();
        }
    }
    init();
}

From source file:com.torrosoft.triviazo.services.music.MusicManager.java

License:Open Source License

/**
 * Stops and disposes the current music being played, if any.
 *//*w  ww  .j ava 2s  . co m*/
public final void stop() {
    if (musicBeingPlayed != null) {
        final Music musicResource = musicBeingPlayed.getMusicResource();

        musicResource.stop();
        musicResource.dispose();
        musicBeingPlayed = null;
    }
}

From source file:com.vlaaad.dice.managers.SoundManager.java

License:Open Source License

public void stopMusic(String name) {
    Music music = musics.get(name);
    if (music == null) {
        Logger.error("there is no music for " + name);
        return;//from   w  ww.j a  v a 2 s .  com
    }
    music.stop();
    playingMusics.remove(music);
    disabledMusics.remove(music);
}

From source file:com.vlaaad.dice.managers.SoundManager.java

License:Open Source License

public void stopMusicBeautifully(String name, Stage stage) {
    final Music music = musics.get(name);
    if (music == null) {
        Logger.error("there is no music for " + name);
        return;/*  ww  w . ja v  a2 s  .  co m*/
    }
    final float initialVolume = music.getVolume();
    Action action = new TemporalAction(2f, Interpolation.linear) {
        @Override
        protected void update(float percent) {
            music.setVolume(initialVolume - percent * initialVolume);
        }

        @Override
        protected void end() {
            music.stop();
            playingMusics.remove(music);
            disabledMusics.remove(music);
        }
    };
    stage.addAction(action);
    replaceAction(music, action);
}

From source file:de.fgerbig.spacepeng.services.MusicManager.java

License:Apache License

/**
 * Stops and disposes the current music being played, if any.
 *//*ww  w.  j av a 2 s  . c  om*/
public void stop() {
    if (musicKeyBeingPlayed != null) {
        Gdx.app.log(Const.NAME, "Stopping current music");
        Music music = musicKeyBeingPlayed.getMusic();
        music.stop();
        lastMusicKeyBeingPlayed = musicKeyBeingPlayed;
        musicKeyBeingPlayed = null;
    }
}

From source file:dk.gruppeseks.bodtrd.managers.AudioPlayer.java

private void handleAudioTask(AssetManager am, AudioTask audioTask) {
    AudioAction audioAction = audioTask.getAudioAction();
    if (audioTask.getAudioType() == AudioType.SOUND) {

        Sound sound = am.get(audioTask.getFileName(), Sound.class);
        switch (audioAction) {
        case PLAY:
            sound.play();//from   w  w w. j ava 2s . c  o  m
            break;
        case RESUME:
            sound.resume();
            break;
        case PAUSE:
            sound.pause();
            break;
        case STOP:
            sound.stop();
            break;
        case LOOP:
            sound.loop();
            break;
        case DISPOSE:
            sound.dispose();
            break;
        default:
            break;
        }
    } else {
        Music music = am.get(audioTask.getFileName(), Music.class);
        switch (audioAction) {
        case PLAY:
            music.play();
            break;
        case LOOP:
            music.play();
            music.setLooping(true);
            break;
        case PAUSE:
            music.pause();
            break;
        case STOP:
            music.stop();
            break;
        default:
            break;
        }
    }
}

From source file:fr.plafogaj.screens.MainMenu.java

License:Open Source License

public void stopAmbianceMusic() {
    for (Music m : m_ambianceMusicList)
        m.stop();
}