Listing 1. Jcd.java


package Jcd;                                 //  1
/**                                              2
  Jcd - Java CD Audio Player                     3
  Michael Hamilton   (michael@actrix.gen.nz).    4
  All rights reserved.  See the README for details
 */                                          //  6
import java.io.*;                            //  8
import Jcd.Drive;                            // 10
public class Jcd {                           // 12
  public static void main(String[] args)     // 14
  {                                          // 15
    Drive cd_drive = new Drive(              // 16
      "/dev/cdrom", 
      "native/ix86-Linux/Jcd_Drive.so",      // 17
      0);                                    // 18
    DataInputStream cmd_stream = 
      new DataInputStream(System.in);        // 19
    String cmd;                              // 20
    try {                                    // 22
      System.out.println(
      "Enter: info play stop pause resume eject"); 
      for (cmd = cmd_stream.readLine();      // 26
           cmd.compareTo("exit") != 0;       // 27
           cmd = cmd_stream.readLine()) {    // 28
        try {                                // 30
          if (cmd.compareTo("play") == 0) {  // 31
            cd_drive.play(1);                // 32
          }                                  // 33
          else if (cmd.startsWith("goto")) { // 34
            try {                            // 35
              cd_drive.play(Integer.parseInt(
                cmd.substring(4).trim()));   // 37
	    }
	    catch (NumberFormatException badnum) {
	      System.out.println("Bad number " +
				 badnum);    // 39
	    }                                // 40
	  }                                  // 41
          else if (cmd.compareTo("stop") == 0) { 
            cd_drive.stop();                 // 43
          }                                  // 44
          else if (cmd.compareTo("pause") == 0) { 
            cd_drive.pause();                // 46
          }                                  // 47
          else if (cmd.compareTo("resume") == 0) {
            cd_drive.resume();               // 49
          }                                  // 50
          else if (cmd.compareTo("eject") == 0) { 
            cd_drive.eject();                // 52
          }                                  // 53
          else if (cmd.compareTo("info") == 0) { 
            System.out.println("CDDB ID    = " +
              cd_drive.cddbID());         
            System.out.println("Num Tracks = " +
              cd_drive.numberOfTracks());
            System.out.println("End address= " +
               cd_drive.cdEndAddress());
            System.out.println("");          // 58
            System.out.println("Track      = " +
              cd_drive.currentTrack());
            System.out.println("Index      = " + 
              cd_drive.currentIndex());
            System.out.println("Address    = " +
              cd_drive.currentAddress());
            System.out.println("Trk address= " + 
              cd_drive.trackAddress());
            System.out.println("Trk length = " + 
              cd_drive.trackLength());
          }                                  // 65
        }                                    // 66
        catch (DriveException drive_problem) {
          System.out.println("Exception: " +
                             drive_problem); // 68
        }                                    // 69
        System.out.println("Enter:");        // 70
      }                                      // 71
    }                                        // 72
    catch (IOException cmd_exception) {      // 73
    }                                        // 74
  }                                          // 75
}                                            // 76