/**
 * AdvancedPlayerThreaded class
 * @author Philip Peng
 * 
 * Extends JLayer 1.0's AdvancedPlayer class
 * Plays file as separate thread and adds getPosition() method 
 * 
 * Created by Philip Peng
 * Last updated: 2007/10/10
 * 
 * Licensed under GNU GPL (Version 3):
 * http://www.gnu.org/licenses/gpl.txt
 * 
 * JLayer website:
 * http://www.javazoom.net/javalayer/sources.html
 * 
 */

import javazoom.jl.player.advanced.AdvancedPlayer;
import javazoom.jl.player.AudioDevice;
import javazoom.jl.decoder.Bitstream;

import java.io.InputStream;

public class AdvancedPlayerThreaded extends AdvancedPlayer {

	/**
	 * Make certain variables accessible
	 */
	private int lastPosition = 0;
	private AudioDevice audio;
	
	/**
	 * Constructor using parent constructor
	 */
	
	
	public AdvancedPlayerThreaded (InputStream stream) throws javazoom.jl.decoder.JavaLayerException {
		super(stream, null);
	}
	
	public int getPosition()
	{
		int position = lastPosition;
		
		AudioDevice out = audio;		
		if (out!=null)
		{
			position = out.getPosition();	
		}
		return position;
	}
	
	public void play() {
		
	}
	
	
}

class AdvancedPlayerThread extends Thread {
	
	public InputStream stream;

	public AdvancedPlayerThread(InputStream stream) {
		this.stream = stream;
	}
	
	public void run() {
		try {
			AdvancedPlayerThreaded foobar = new AdvancedPlayerThreaded(stream);
			foobar.play();
		} catch( Exception e ) {
			e.printStackTrace();
		}
	}
}
