/*
 * Copyright (C) 2025 ctecinf.com.br
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package br.com.ctecinf.jetty.audio;

import java.io.File;
import java.net.URL;

/**
 *
 * @author Cássio Conceição
 * @since 13/06/2023
 * @version 2503
 * @see http://hobbyslotcar.com.br
 */
public class Audio {

    protected AudioRunnable play;

    /**
     * Cria novo objeto audio
     *
     * @return Audio
     */
    public static Audio getInstance() {
        return new Audio();
    }

    /**
     * Executa audio
     *
     * @param audio
     * @throws br.com.ctecinf.jetty.audio.AudioException
     */
    public void play(String audio) throws AudioException {
        this.play(new AudioStream(audio));
    }

    /**
     * Executa audio
     *
     * @param audio
     * @throws br.com.ctecinf.jetty.audio.AudioException
     */
    public void play(File audio) throws AudioException {
        this.play(new AudioStream(audio));
    }

    /**
     * Executa audio
     *
     * @param audio
     * @throws br.com.ctecinf.jetty.audio.AudioException
     */
    public void play(URL audio) throws AudioException {
        this.play(new AudioStream(audio));
    }

    /**
     * Executa audio
     *
     * @param audioStream
     */
    public void play(AudioStream audioStream) {
        play = new AudioRunnable(audioStream);
        Thread thread = new Thread(play);
        thread.start();
    }

    /**
     * Pára a execução
     */
    public void stop() {
        play.stop();
    }
}
