package djmania.sandbox.old;

/**
 * ThreadedPlayer tester.
 * <p>
 * Just tests the ThreadedPlayer thread using the sample "foobar.mp3" file.
 * <p>
 * Licensed under <A HREF="http://www.gnu.org/licenses/gpl.txt">GNU GPL (Version 3)</A>.
 * <p>
 * @author	Philip Peng
 * @version	1.0
 * @deprecated
 * 
 */

public class ThreadedPlayerTest {

	public static void main (String[] args) {
		
		// Testing file
		String file = "resublimity.mp3";
		
		// Thread
		ThreadedPlayer foobar = new ThreadedPlayer();
		
		// Sets stream
		if (foobar.setStream(file)==1) {
			
			// Starting playback
			System.out.println("========================================");
			System.out.println("Starting playback of " + file);
			System.out.println("========================================");
			foobar.start();
			
			// Suspending and resuming thread
			try {
				System.out.println("3 second wait");
				Thread.sleep(3000);
				System.out.println("foobar.suspend()");
				foobar.suspend();
				System.out.println("3 second wait");
				Thread.sleep(3000);
				System.out.println("foobar.resume()");
				foobar.resume();
				System.out.println("3 second wait");
				Thread.sleep(3000);
				System.out.println("foobar.suspend()");
				foobar.suspend();
				System.out.println("3 second wait");
				Thread.sleep(3000);
				System.out.println("foobar.resume()");
				foobar.resume();
				System.out.println("3 second wait");
				Thread.sleep(3000);
			} catch (InterruptedException e) {
				e.getMessage();
			}
			
			// Report position
			while (foobar.isAlive()) {
				System.out.println(foobar.getPosition());				
				// Note: Without the sleep pause, the JVM
				// becomes an _intensive_ resource hog
				// and unnecessarily updates multiple times
				// every millisecond. Better to check
				// ever 1-2 milliseconds instead  
				try { Thread.sleep(2); } catch (Exception e) {}
			}
			
			// Finished playback
			System.out.println("========================================");
			System.out.println("Finished playback of " + file);
			System.out.println("========================================");
		
		// If fail to set
		} else {
			
			// Error.
			System.err.println("Unable to set up file stream.");
			
		}
		
	} // End main method
	
} // End ThreadedPlayerTest class
