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

import java.io.FileInputStream;
import javazoom.jl.player.Player;
import java.io.FileInputStream;

public class PlayerThread extends Player {
	
	
	PlayerThreaded foobar;
	
	/**
	 * Constructor
	 * @param stream	FileInputStream. 
	 */
	public PlayerThread (FileInputStream stream)
	throws javazoom.jl.decoder.JavaLayerException {
		super(stream, null);
	}
	
	/**
	 * Constructor
	 * @param file	String of file location.
	 */
	public PlayerThread (String file)
	throws javazoom.jl.decoder.JavaLayerException, java.io.FileNotFoundException {
		super(convertStringToStream(file), null);
	}
	
	/**
	 * Convert String object to FileInputStream object
	 * @param file	String of file location.
	 * @return stream	File location as a FileInputStream
	 */
	static private FileInputStream convertStringToStream(String file)
	throws java.io.FileNotFoundException {
		FileInputStream stream = new FileInputStream(file);
		return stream;
	}
	
	public void play() {
		foobar = new PlayerThreaded(this);
		foobar.start();
	}
	
	public void playParent() {
		try {
			super.play();
		} catch( Exception e ) {
			e.printStackTrace();
		}
	}
	
}


class PlayerThreaded extends Thread {

	public PlayerThread foobar;
	int position = 0;
	
	public PlayerThreaded (PlayerThread foobar) {
		this.foobar = foobar;
	}
	
	public void run() {
		try {
			foobar.playParent();
		} catch( Exception e ) {
			e.printStackTrace();
		}
	}
	
}