package djmania.sandbox.old;


import java.util.Scanner;
import java.io.File;

/**
 * PlayerThreaded tester.
 * <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 PlayerThreadedTest {

	/**
	 * Asks for location to song file, creates a PlayerThreaded object
	 * for that file, then plays the file. Tests PlayerThreaded's
	 * .pause(), .resume(), .play(), .getPosition(), and .close() methods.
	 */
	public static void main(String[] args) {
		
		do {
			// Ask for file name
			System.out.println("Type in location to song file (\"quit\" to exit):");
			Scanner input = new Scanner(System.in);
			String file = input.nextLine();
			
			if (file.equals("quit")) {
				break;
			}
			// Check if the file exists
			File f = new File(file);
			if (f.canRead()) {
				
				// Try to playback file
				try {
					// Instantiate new PlayerThreaded
					PlayerThreaded foobar = new PlayerThreaded(file);
					
					// Start PlayerThreaded
					foobar.play();
					
					// Start playback
					System.out.println("========================================");
					System.out.println("Starting playback of " + file);
					System.out.println("========================================");
					
					// Test methods
					System.out.println("5 second wait");
					Thread.sleep(5000);
					System.out.println("foobar.pause()");
					foobar.pause();
					System.out.println("5 second wait");
					Thread.sleep(5000);
					System.out.println("foobar.resume()");
					foobar.resume();
					System.out.println("5 second wait");
					Thread.sleep(5000);
					System.out.println("foobar.pause()");
					foobar.pause();
					System.out.println("5 second wait");
					Thread.sleep(5000);
					System.out.println("foobar.play()");
					foobar.play();
					System.out.println("5 second wait");
					Thread.sleep(5000);
					
					
					// Print progress
					System.out.println("Print foobar.getPosition()");
					while (!foobar.isComplete()) {
						System.out.println(foobar.getPosition());
					}
					
					System.out.println("========================================");
					System.out.println("Finished playback of " + file);
					System.out.println("========================================");
					
				} catch( Exception e ) {
					e.printStackTrace();
				}
				
			} else {
				System.out.println("Error: File " + file + " cannot be read.\n"); 
			}
			
		} while (true); // Keep asking

	} // End public static void main(String[] args)

}
