Package crazyOrb.musikplayer

Source Code of crazyOrb.musikplayer.MPmitMP3

package crazyOrb.musikplayer;

import java.io.BufferedInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.AudioDevice;
import javazoom.jl.player.FactoryRegistry;
import javazoom.jl.player.advanced.AdvancedPlayer;

/**
*
* @author Daniel
*/
public class MPmitMP3 implements MusicInterface {

    private boolean on;
    PlayList pl = new PlayList();
    AdvancedPlayer p;
    InputStream in;
    AudioDevice device;

    public void togglePlayState() {

        if (on == false) {
            try {
                p.play();
            } catch (JavaLayerException ex) {
                Logger.getLogger(MPmitMP3.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            p.stop();
            on = false;
        }
    }

    public boolean setTrack(String trackTitle) {
        try {
            in = this.getClass().getResourceAsStream(pl.getPath(trackTitle));
            BufferedInputStream in = new BufferedInputStream(this.in);
            device = FactoryRegistry.systemRegistry().createAudioDevice();
            this.p = new AdvancedPlayer(in, device);
        } catch (JavaLayerException ex) {
            Logger.getLogger(MPmitMP3.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
        return true;
    }

    public ArrayList<String> getTrackPaths() {
        return pl.getTrackPaths();
    }

    public ArrayList<String> getTracks() {
        return pl.getTrackNames();
    }
}
TOP

Related Classes of crazyOrb.musikplayer.MPmitMP3

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.