package djmania.sandbox.testing;

import djmania.file.AudioReader;
import static djmania.file.FileTools.sleep;
import static java.lang.System.out;

/**
 * (Tester) AudioReader class tester.
 * <p>
 * Tests all the methods of the {@link AudioReader} class. 
 * Tests using the <A HREF="../../../../test/resublimity.mp3">test/resublimity.mp3</A> 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 27-Oct-07
 * 
 */

public class AudioReaderTester {

	public static void main(String[] args) {
		String testMP3 = "test\\resublimity.mp3";
		AudioReader foobar = new AudioReader();
		
		// Setup AudioReader
		int setup = foobar.setAudioFile(testMP3);
		
		if (setup==1) {

			// Start playback
			out.println("Starting playback of "
					+ foobar.getAudioFile()
					+ " of format "
					+ foobar.getAudioType()
					);
			foobar.play();
			sleep();
			
			// Pause playback
			out.println("foobar.pause()");
			foobar.pause();
			sleep();
			
			// Resume playback
			out.println("foobar.resume()");
			foobar.resume();
			sleep();
			
			// Force stop playback
			//out.println("foobar.forceStop()");
			//foobar.forceStop();
			
			// Get position
			out.println("while not foobar.isDone(), loop foobar.getPosition() ");
			while (!foobar.isDone()) {
				out.println(foobar.getPosition());
				sleep(2); // For performance sanity
			}
			
			// Finish playback
			out.println("Finished playback of "	+ foobar.getAudioFile());
			
		} else if (setup==-1) {
			out.println("Error: File " + testMP3 + " not found"); 
		} else if (setup==0) {
			out.println("Error: Unable to set playback stream.");
		} else {
			out.println("WTF??? Failure of .setAudioFile(String) method!");
		}
		
	}

}
