/**
 * 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.FileInputStream;

public class AdvancedPlayerThreaded extends AdvancedPlayer {

	/**
	 * Make certain variables accessible
	 */
	private int lastPosition = 0;
	private AudioDevice audio;
	private boolean complete = false;
	public AdvancedPlayerThread foobar;
	
	/**
	 * Constructor using parent constructor
	 */
	
	
	public AdvancedPlayerThreaded (FileInputStream 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() {
		foobar = new AdvancedPlayerThread(this);
		foobar.start();
	}
	
	
	public void playParent() {
		try {
			super.play();
		} catch( Exception e ) {
			e.printStackTrace();
		}
	}
	
	public synchronized boolean isComplete()
	{
		return complete;	
	}
	
	
}
