001package ca.bc.webarts;
002
003import ca.bc.webarts.widgets.Util;
004
005/** A Commdaline NON-gui version of JOggPlayer Vorbis Ogg sound file. **/
006public class JOggPlayerCommandline
007{
008  public static String piSndOggRootDir_ = "/mnt/nas/snd/ogg";
009  /**  The separate thread that the Player livesin . */
010  //Thread playerThread_ = null;
011
012
013  public void JOggPlayerCommandline(){}
014
015  public static void main(String cmdArgs[])
016  {
017    int retVal = 1;
018    int testPattern = 0;
019    JOggPlayerListener player_ = JOggPlayerListener.getInstance();
020    String piTunePath = "";
021
022    try
023    {
024    switch (cmdArgs[0])
025    {
026      case "testtune1":
027      case "testtunes1":
028      case "testtune2":
029      case "testtunes2":
030      case "tune":
031      case "tunes":
032        // Play the tunes
033        if (cmdArgs.length >1)
034        {
035          for (int i = 1; i < cmdArgs.length; i++)
036          {
037            piTunePath = piSndOggRootDir_+"/"+cmdArgs[i];
038            player_.addToPlaylist(piTunePath);
039          }
040        }
041        player_.play_sound();
042        System.out.println("JOggPlayerCommand  has started playing");
043        retVal = 0;
044        break;
045
046      case "testtune3":
047      case "testtunes3":
048        // Play the tunes
049        if (cmdArgs.length >1)
050        {
051          String [] piTunePaths = new String [ cmdArgs.length-1];
052          for (int i = 1; i < cmdArgs.length; i++)
053          {
054            piTunePaths[i-1] = piSndOggRootDir_+"/"+cmdArgs[i];
055          }
056          player_.addDirFilesToPlaylist(piTunePaths, true);
057        }
058        player_.play_sound();
059        System.out.println("JOggPlayerCommand  has started playing");
060        retVal = 0;
061        break;
062
063      case "stop":
064        player_.signalStopPlay();
065        retVal = 0;
066        break;
067
068      default:
069        System.out.println("ERROR on commandline:  1st commandOption must  be [tune, tunes, stop]");
070    }
071    }
072    catch (Exception ex)
073    {
074      System.out.println("\n\nERROR on commandline:  Please provide a command: must  be [tune, tunes, stop]");
075      System.out.println("             tune requires an additional path to a tune");
076      System.out.println("             tunes requires multiple paths to tunes to add to the playlist");
077    }
078
079    if(retVal==0)
080    {
081      // do some tests
082      if(testPattern==1
083         || "testtune1".equalsIgnoreCase(cmdArgs[0])
084         || "testtunes1".equalsIgnoreCase(cmdArgs[0])
085        )
086      {
087        System.out.println("JOggPlayerCommand Waiting 10sec while tune plays");
088        Util.sleep(10*1000);
089        System.out.println("\nJOggPlayerCommand   SENDING toggle pause");
090        player_.signalLoopPaused();
091        Util.sleep(5*1000);
092        System.out.println("\nJOggPlayerCommand   SENDING toggle pause ");
093        player_.signalLoopPaused();
094
095        Util.sleep(5*1000);
096        System.out.println("\nJOggPlayerCommand   SENDING STOP");
097        player_.signalStopPlay();
098      }
099
100      /*  Test 2  */
101      else if(testPattern==2
102               || "testtune2".equalsIgnoreCase(cmdArgs[0])
103               || "testtunes2".equalsIgnoreCase(cmdArgs[0])
104              )
105      {
106        System.out.println("JOggPlayerCommand Waiting 5sec while tune plays");
107        Util.sleep(5*1000);
108        System.out.println("\nJOggPlayerCommand   SENDING NEXT");
109        player_.signalNextInPlaylist();
110        Util.sleep(5*1000);
111        System.out.println("\nJOggPlayerCommand   SENDING NEXT");
112        player_.signalNextInPlaylist();
113        Util.sleep(5*1000);
114        System.out.println("\nJOggPlayerCommand   SENDING Previous");
115        player_.signalPreviousInPlaylist();
116        //while(player_!=null && !player_.isStopped()) Util.sleep(250);
117        //Util.sleep(250);
118        //player_.play_sound(1);
119        while(player_!=null && player_.isPlaying())
120        {
121          Util.sleep(5*1000);
122          System.out.print(player_.retrieveCurrentTunePlayTimeInMiliSeconds()/1000+ "("+ player_.retrieveTuneProgressRatio()+")   ");
123        }
124        System.out.println("\nJOggPlayerCommand player is done.");
125
126      }
127
128      /*  Test 2  */
129      else if(testPattern==3)
130      {
131      }
132      else
133      {
134        System.out.println("\nJOggPlayerCommand   waiting until song"+("tunes".equalsIgnoreCase(cmdArgs[0])?"s":"")+
135                            " are done");
136
137        while(player_!=null && player_.isPlaying())
138        {
139          Util.sleep(5*1000);
140          System.out.print(player_.retrieveCurrentTunePlayTimeInMiliSeconds()/1000+ "("+ player_.retrieveTuneProgressRatio()+")   ");
141        }
142        System.out.println("\nJOggPlayerCommand player is done.");
143      }
144
145    }
146
147  }
148
149
150}