All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.harium.etyl.sound.model.Music Maven / Gradle / Ivy

There is a newer version: 1.10.0.1
Show newest version
package com.harium.etyl.sound.model;

import com.harium.etyl.loader.MultimediaLoader;
import com.harium.etyl.loader.async.AsyncResource;

public class Music implements AsyncResource {

    private boolean playOnLoad = false;
    private boolean loaded = false;
    private com.badlogic.gdx.audio.Music music;

    public Music(String path) {
        MultimediaLoader.getInstance().loadMusicAsync(path, this);
    }

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

    public boolean isPlaying() {
        if (music == null) {
            return false;
        }
        return music.isPlaying();
    }

    public void stop() {
        music.stop();
    }

    public void dispose() {
        music.dispose();
    }

    @Override
    public void onLoad(com.badlogic.gdx.audio.Music music) {
        this.music = music;
        this.music.setLooping(true);
        this.loaded = true;

        if (playOnLoad) {
            play();
        }
    }

    @Override
    public Class resourceClass() {
        return com.badlogic.gdx.audio.Music.class;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy