Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 27

Thread: Automatic audio file player not working

  1. #1
    Member
    Join Date
    Jul 2013
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Automatic audio file player not working

    So this program is supposed to play back a series of audio files at certain times of the day. I'm aware there are probably ways I could have written it better, but I'm rather new to this, and I'd be happy to just get this working. I've already worked with audio and created a program to take microphone input and send it back out the speakers, so I'm not sure what the problem is here.

    Since the code is obscenely long, I will try to give you an idea of what happens:

    1. main() executes and immediately calls on WaitingMachine's waitFor() method to feed an int into a variable.

    2. waitFor() loops in a while() loop until a certain time of day is reached. The while() loop repeats monitoring the time from a Calendar object until conditions are satisfied that reflect the fact that the time is what it should be for the program to proceed.

    3. At the correct time, waitFor() returns a value to main(), which immediately feeds that value to a FilePlayer object constructor, and then invokes the playAudio() method on that object.

    4. FilePlayer contains a list of pre-initialized static files that always play, and a few that are initialized in the instance methods that play depending on the time of day. FilePlayer's constructor has set the time as an instance var in its class, and then the main() function calls the playAudio() method, which reads the value of that var to determine which audio clips to play.

    That's it. The clips ought to play and then function should drop back through to main() which should do it all over again, being inside an infinite for() loop. However, if I test this program by setting my computer clock to a few seconds prior to one of the correct times, then activating the program, nothing happens at that time. The code compiles fine, but nothing whatsoever happens. No audio is played.

    import javax.sound.sampled.*;
    import java.util.Calendar;
    import java.io.File;
    import java.io.IOException;
     
    class FilePlayer { 
     
    private static File theTimeIsFile, timeForFile, repeatFile, dexFile, hydFile, gabFile, andFile;
    private static AudioInputStream theTimeIsStream, timeForStream, repeatStream, dexStream, hydStream, gabStream, andStream;
    private static Clip theTimeIsClip, timeForClip, repeatClip, dexClip, hydClip, gabClip, andClip;
    private static AudioFormat theTimeIsFormat, timeForFormat, repeatFormat, dexFormat, hydFormat, gabFormat, andFormat;
    private static DataLine.Info theTimeIsInfo, timeForInfo, repeatInfo, dexInfo, hydInfo, gabInfo, andInfo;
    private int time;
     
    static {
     
     
    theTimeIsFile = new File("C:/PillMonitor/ProgramData/Audio/TheTimeIs.wav");
    timeForFile = new File("C:/PillMonitor/ProgramData/Audio/TimeFor.wav");
    repeatFile = new File("C:/PillMonitor/ProgramData/Audio/Repeat.wav");
    dexFile = new File("C:/PillMonitor/ProgramData/Audio/dex.wav");
    hydFile = new File("C:/PillMonitor/ProgramData/Audio/hyd.wav");
    gabFile = new File("C:/PillMonitor/ProgramData/Audio/gab.wav");
    andFile = new File("C:/PillMonitor/ProgramData/Audio/and.wav");
     
    try {
     
    theTimeIsStream = AudioSystem.getAudioInputStream(theTimeIsFile);
    timeForStream = AudioSystem.getAudioInputStream(timeForFile);
    repeatStream = AudioSystem.getAudioInputStream(repeatFile);
    dexStream = AudioSystem.getAudioInputStream(dexFile);
    hydStream = AudioSystem.getAudioInputStream(hydFile);
    gabStream = AudioSystem.getAudioInputStream(gabFile);
    andStream = AudioSystem.getAudioInputStream(andFile);
    } catch(UnsupportedAudioFileException ex) {
    System.out.println("Audio files are unsupported.");
    System.exit(1);
    } catch(IOException ex) {
    System.out.println("IO Exception in FilePlayer SIB, AudioStream initialization.");
    System.exit(1);
    }
     
    theTimeIsFormat = theTimeIsStream.getFormat();
    timeForFormat = timeForStream.getFormat();
    repeatFormat = repeatStream.getFormat();
    dexFormat  = dexStream.getFormat();
    hydFormat = hydStream.getFormat();
    gabFormat = gabStream.getFormat();
    andFormat = andStream.getFormat();
     
    theTimeIsInfo = new DataLine.Info(Clip.class, theTimeIsFormat);
    timeForInfo = new DataLine.Info(Clip.class, timeForFormat);
    repeatInfo = new DataLine.Info(Clip.class, repeatFormat);
    dexInfo = new DataLine.Info(Clip.class, dexFormat);
    hydInfo = new DataLine.Info(Clip.class, hydFormat);
    gabInfo = new DataLine.Info(Clip.class, gabFormat);
    andInfo = new DataLine.Info(Clip.class, andFormat);
     
    try {
     
    theTimeIsClip = (Clip) AudioSystem.getLine(theTimeIsInfo);
    timeForClip = (Clip) AudioSystem.getLine(timeForInfo);
    repeatClip = (Clip) AudioSystem.getLine(repeatInfo);
    dexClip = (Clip) AudioSystem.getLine(dexInfo);
    hydClip = (Clip) AudioSystem.getLine(hydInfo);
    gabClip = (Clip) AudioSystem.getLine(gabInfo);
    andClip = (Clip) AudioSystem.getLine(andInfo);
    } catch(LineUnavailableException ex) {
    System.out.println("Audio line unavailable exception in FilePlayer static initialization block.");
    System.exit(1);
     
    }}
     
    public FilePlayer(int time) {
    this.time = time;
    try{
    theTimeIsClip.open(theTimeIsStream);
    timeForClip.open(timeForStream);
    repeatClip.open(repeatStream);
    } catch(LineUnavailableException ex) {
    System.out.println("Audio line unavailable exception in FilePlayer constructor.");
    System.exit(1);
    } catch(IOException ex) {
    System.out.println("IO Exception in FilePlayer constructor.");
    System.exit(1);
    }
    }
     
    public void playAudio() {
     
    switch(time) {
     
    case 7: try {play07();}
                 catch(IOException ex) {System.out.println("IOEx in FP switchblock (method play07())."); System.exit(1);}
                 catch(UnsupportedAudioFileException ex) {System.out.println("USAF-Ex in FP switch method 07."); System.exit(1);}
                 catch(LineUnavailableException ex) {System.out.println("LU-Ex FP SB m-7."); System.exit(1);}
                 catch(InterruptedException ex) {System.out.println("INT-Ex FP SB m-7."); System.exit(1);}
                 break;
    case 11: try {play11();}
                 catch(IOException ex) {System.out.println("IOEx in FP switchblock (method play11())."); System.exit(1);}
                 catch(UnsupportedAudioFileException ex) {System.out.println("USAF-Ex in FP switch method 11."); System.exit(1);}
                 catch(LineUnavailableException ex) {System.out.println("LU-Ex FP SB m-11."); System.exit(1);}
                 catch(InterruptedException ex) {System.out.println("INT-Ex FP SB m-11."); System.exit(1);}
                 break;
    case 15: try {play15();}
                  catch(IOException ex) {System.out.println("IOEx in FP switchblock (method play15())."); System.exit(1);}
                  catch(UnsupportedAudioFileException ex) {System.out.println("USAF-Ex in FP switch method 15."); System.exit(1);}
                  catch(LineUnavailableException ex) {System.out.println("LU-Ex FP SB m-15."); System.exit(1);}
                  catch(InterruptedException ex) {System.out.println("INT-Ex FP SB m-15."); System.exit(1);}
                  break;
    case 19: try {play19();}
                 catch(IOException ex) {System.out.println("IOEx in FP switchblock (method play19())."); System.exit(1);}
                 catch(UnsupportedAudioFileException ex) {System.out.println("USAF-Ex in FP switch method 19."); System.exit(1);}
                 catch(LineUnavailableException ex) {System.out.println("LU-Ex FP SB m-19."); System.exit(1);}
                 catch(InterruptedException ex) {System.out.println("INT-Ex FP SB m-19."); System.exit(1);}
                 break;
    }
     
    }
     
    private void play07() throws UnsupportedAudioFileException, LineUnavailableException, InterruptedException, IOException {
     
    for(int i = 0; i < 2; i++) {
     
    theTimeIsClip.start();
    wait(theTimeIsClip.getMicrosecondLength() / 1000);
     
    Clip timeClip;
    File timeFile = new File("C:/PillMonitor/ProgramData/Audio/07.wav");
    AudioInputStream stream = AudioSystem.getAudioInputStream(timeFile);
    AudioFormat format = stream.getFormat();
    DataLine.Info infos = new DataLine.Info(Clip.class, format);
    timeClip = (Clip) AudioSystem.getLine(infos);
    timeClip.open(stream);
    timeClip.start();
    wait(timeClip.getMicrosecondLength() / 1000);
     
    timeForClip.start();
    wait(timeForClip.getMicrosecondLength() / 1000);
     
    dexClip.start();
    wait(dexClip.getMicrosecondLength() / 1000);
     
    andClip.start();
    wait(andClip.getMicrosecondLength() / 1000);
     
    hydClip.start();
    wait(hydClip.getMicrosecondLength() / 1000);
     
    if(i != 0)
    	break;
     
    repeatClip.start();
    wait(repeatClip.getMicrosecondLength() / 1000);
    	}
    }
     
    private void play11() throws UnsupportedAudioFileException, LineUnavailableException, InterruptedException, IOException {
     
    for(int i = 0; i < 2; i++) {
     
    theTimeIsClip.start();
    wait(theTimeIsClip.getMicrosecondLength() / 1000);
     
    Clip timeClip;
    File timeFile = new File("C:/PillMonitor/ProgramData/Audio/11.wav");
    AudioInputStream stream = AudioSystem.getAudioInputStream(timeFile);
    AudioFormat format = stream.getFormat();
    DataLine.Info infos = new DataLine.Info(Clip.class, format);
    timeClip = (Clip) AudioSystem.getLine(infos);
    timeClip.open(stream);
    timeClip.start();
    wait(timeClip.getMicrosecondLength() / 1000);
     
    timeForClip.start();
    wait(timeForClip.getMicrosecondLength() / 1000);
     
    hydClip.start();
    wait(hydClip.getMicrosecondLength() / 1000);
     
    if(i != 0)
    	break;
     
    repeatClip.start();
    wait(repeatClip.getMicrosecondLength() / 1000);
    	}
    }
     
    private void play15() throws UnsupportedAudioFileException, LineUnavailableException, InterruptedException, IOException {
     
    for(int i = 0; i < 2; i++) {
     
    theTimeIsClip.start();
    wait(theTimeIsClip.getMicrosecondLength() / 1000);
     
    Clip timeClip;
    File timeFile = new File("C:/PillMonitor/ProgramData/Audio/15.wav");
    AudioInputStream stream = AudioSystem.getAudioInputStream(timeFile);
    AudioFormat format = stream.getFormat();
    DataLine.Info infos = new DataLine.Info(Clip.class, format);
    timeClip = (Clip) AudioSystem.getLine(infos);
    timeClip.open(stream);
    timeClip.start();
    wait(timeClip.getMicrosecondLength() / 1000);
     
    timeForClip.start();
    wait(timeForClip.getMicrosecondLength() / 1000);
     
    hydClip.start();
    wait(hydClip.getMicrosecondLength() / 1000);
     
    if(i != 0)
    	break;
     
    repeatClip.start();
    wait(repeatClip.getMicrosecondLength() / 1000);
    	}
    }
     
    private void play19() throws UnsupportedAudioFileException, LineUnavailableException, InterruptedException, IOException {
     
    for(int i = 0; i < 2; i++) {
     
    theTimeIsClip.start();
    wait(theTimeIsClip.getMicrosecondLength() / 1000);
     
    Clip timeClip;
    File timeFile = new File("C:/PillMonitor/ProgramData/Audio/15.wav");
    AudioInputStream stream = AudioSystem.getAudioInputStream(timeFile);
    AudioFormat format = stream.getFormat();
    DataLine.Info infos = new DataLine.Info(Clip.class, format);
    timeClip = (Clip) AudioSystem.getLine(infos);
    timeClip.open(stream);
    timeClip.start();
    wait(timeClip.getMicrosecondLength() / 1000);
     
    timeForClip.start();
    wait(timeForClip.getMicrosecondLength() / 1000);
     
    hydClip.start();
    wait(hydClip.getMicrosecondLength() / 1000);
     
    andClip.start();
    wait(andClip.getMicrosecondLength() / 1000);
     
    gabClip.start();
    wait(gabClip.getMicrosecondLength() / 1000);
     
    if(i != 0)
    	break;
     
    repeatClip.start();
    wait(repeatClip.getMicrosecondLength() / 1000);
    	}
    }
    }
     
    class WaitingMachine {
     
    private static Calendar calendar = Calendar.getInstance();
     
    public static int waitFor() {
     
    while(calendar.get(Calendar.HOUR_OF_DAY) != 7 && calendar.get(Calendar.HOUR_OF_DAY) != 11 && calendar.get
     
    (Calendar.HOUR_OF_DAY) != 15 && calendar.get(Calendar.HOUR_OF_DAY) != 19 || calendar.get(Calendar.MINUTE) > 0) {
    continue;
    }
     
    return calendar.get(Calendar.HOUR_OF_DAY);
     
    }
     
     
     
    }
     
    public class PillMonitor {
     
    public static void main(String[] args) {
     
    System.out.println("Pill Monitor v1.0.  Do not close this window.");
     
    for(;;) {
    int pillTimer = WaitingMachine.waitFor();
    FilePlayer player = new FilePlayer(pillTimer);
    player.playAudio();
    }
     
    	}
    }

    Thanks!

    -summit45


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Automatic audio file player not working

    Quote Originally Posted by summit45 View Post
    I test this program by setting my computer clock to a few seconds prior to one of the correct times, then activating the program, nothing happens at that time.
    Are you giving the program time to execute before the time advances too far? Add some println statements to see where execution stops and verify if/when the methods are being called.

  3. #3
    Member
    Join Date
    Jul 2013
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Automatic audio file player not working

    Tried it, thanks for the suggestion. That helped a lot - now the code runs when the system clock reaches its right time!

    So it looks like my code is getting hung up on my attempted use of the wait() method. Basically, I put that there because I was afraid if I didn't have it, when one audio file started playing, function would just fall through and continue executing, thus I'd have all audio files in the method playing at once. I'll give it a try without the wait() methods while I'm waiting for an answer, but if I turn out to be right and I do need to make the program wait to continue execution until the audio is done playing, how can I do it?

    -summit45

    --- Update ---

    Well I got the audio playing, but it's only playing the clip that's actually set up and initialized in the method. The other clips aren't playing. Also I have a problem in the while() loop where I need to make it so that the loop only breaks at x:00.00 - so that it will all only play through one time and not the whole hour. I'll sleep on it, because it's 3:00 AM here, and check back here in the morning.

    For reference, here's the code as it stands right now, what I've been doing to it:

    import javax.sound.sampled.*;
    import java.util.Calendar;
    import java.io.File;
    import java.io.IOException;
     
    class FilePlayer { 
     
    private static File theTimeIsFile, timeForFile, repeatFile, dexFile, hydFile, gabFile, andFile;
    private static AudioInputStream theTimeIsStream, timeForStream, repeatStream, dexStream, hydStream, gabStream, andStream;
    private static Clip theTimeIsClip, timeForClip, repeatClip, dexClip, hydClip, gabClip, andClip;
    private static AudioFormat theTimeIsFormat, timeForFormat, repeatFormat, dexFormat, hydFormat, gabFormat, andFormat;
    private static DataLine.Info theTimeIsInfo, timeForInfo, repeatInfo, dexInfo, hydInfo, gabInfo, andInfo;
    private int time;
     
    static {
     
     
    theTimeIsFile = new File("C:/PillMonitor/ProgramData/Audio/TheTimeIs.wav");
    timeForFile = new File("C:/PillMonitor/ProgramData/Audio/TimeFor.wav");
    repeatFile = new File("C:/PillMonitor/ProgramData/Audio/Repeat.wav");
    dexFile = new File("C:/PillMonitor/ProgramData/Audio/dex.wav");
    hydFile = new File("C:/PillMonitor/ProgramData/Audio/hyd.wav");
    gabFile = new File("C:/PillMonitor/ProgramData/Audio/gab.wav");
    andFile = new File("C:/PillMonitor/ProgramData/Audio/and.wav");
     
    try {
     
    theTimeIsStream = AudioSystem.getAudioInputStream(theTimeIsFile);
    timeForStream = AudioSystem.getAudioInputStream(timeForFile);
    repeatStream = AudioSystem.getAudioInputStream(repeatFile);
    dexStream = AudioSystem.getAudioInputStream(dexFile);
    hydStream = AudioSystem.getAudioInputStream(hydFile);
    gabStream = AudioSystem.getAudioInputStream(gabFile);
    andStream = AudioSystem.getAudioInputStream(andFile);
    } catch(UnsupportedAudioFileException ex) {
    System.out.println("Audio files are unsupported.");
    System.exit(1);
    } catch(IOException ex) {
    System.out.println("IO Exception in FilePlayer SIB, AudioStream initialization.");
    System.exit(1);
    }
     
    theTimeIsFormat = theTimeIsStream.getFormat();
    timeForFormat = timeForStream.getFormat();
    repeatFormat = repeatStream.getFormat();
    dexFormat  = dexStream.getFormat();
    hydFormat = hydStream.getFormat();
    gabFormat = gabStream.getFormat();
    andFormat = andStream.getFormat();
     
    theTimeIsInfo = new DataLine.Info(Clip.class, theTimeIsFormat);
    timeForInfo = new DataLine.Info(Clip.class, timeForFormat);
    repeatInfo = new DataLine.Info(Clip.class, repeatFormat);
    dexInfo = new DataLine.Info(Clip.class, dexFormat);
    hydInfo = new DataLine.Info(Clip.class, hydFormat);
    gabInfo = new DataLine.Info(Clip.class, gabFormat);
    andInfo = new DataLine.Info(Clip.class, andFormat);
     
    try {
     
    theTimeIsClip = (Clip) AudioSystem.getLine(theTimeIsInfo);
    timeForClip = (Clip) AudioSystem.getLine(timeForInfo);
    repeatClip = (Clip) AudioSystem.getLine(repeatInfo);
    dexClip = (Clip) AudioSystem.getLine(dexInfo);
    hydClip = (Clip) AudioSystem.getLine(hydInfo);
    gabClip = (Clip) AudioSystem.getLine(gabInfo);
    andClip = (Clip) AudioSystem.getLine(andInfo);
    } catch(LineUnavailableException ex) {
    System.out.println("Audio line unavailable exception in FilePlayer static initialization block.");
    System.exit(1);
     
    }}
     
    public FilePlayer(int time) {
    System.out.println("FilePlayer constructor invoked successfully.");
    this.time = time;
     
    System.out.println("FilePlayer construction complete.");
    }
     
    public void playAudio() {
     
    System.out.println("playAudio() method invoked successfully.  Function falling into switch() block.");
     
    switch(time) {
     
    case 7: try {play07();}
                 catch(IOException ex) {System.out.println("IOEx in FP switchblock (method play07())."); System.exit(1);}
                 catch(UnsupportedAudioFileException ex) {System.out.println("USAF-Ex in FP switch method 07."); System.exit(1);}
                 catch(LineUnavailableException ex) {System.out.println("LU-Ex FP SB m-7."); System.exit(1);}
                 catch(InterruptedException ex) {System.out.println("INT-Ex FP SB m-7."); System.exit(1);}
                 break;
    case 11: try {play11();}
                 catch(IOException ex) {System.out.println("IOEx in FP switchblock (method play11())."); System.exit(1);}
                 catch(UnsupportedAudioFileException ex) {System.out.println("USAF-Ex in FP switch method 11."); System.exit(1);}
                 catch(LineUnavailableException ex) {System.out.println("LU-Ex FP SB m-11."); System.exit(1);}
                 catch(InterruptedException ex) {System.out.println("INT-Ex FP SB m-11."); System.exit(1);}
                 break;
    case 15: try {play15();}
                  catch(IOException ex) {System.out.println("IOEx in FP switchblock (method play15())."); System.exit(1);}
                  catch(UnsupportedAudioFileException ex) {System.out.println("USAF-Ex in FP switch method 15."); System.exit(1);}
                  catch(LineUnavailableException ex) {System.out.println("LU-Ex FP SB m-15."); System.exit(1);}
                  catch(InterruptedException ex) {System.out.println("INT-Ex FP SB m-15."); System.exit(1);}
                  break;
    case 19: try {play19();}
                 catch(IOException ex) {System.out.println("IOEx in FP switchblock (method play19())."); System.exit(1);}
                 catch(UnsupportedAudioFileException ex) {System.out.println("USAF-Ex in FP switch method 19."); System.exit(1);}
                 catch(LineUnavailableException ex) {System.out.println("LU-Ex FP SB m-19."); System.exit(1);}
                 catch(InterruptedException ex) {System.out.println("INT-Ex FP SB m-19."); System.exit(1);}
                 break;
    }
     
    }
     
    private void play07() throws UnsupportedAudioFileException, LineUnavailableException, InterruptedException, IOException {
     
    System.out.println("Function passed to play07().");
     
    for(int i = 0; i < 2; i++) {
     
    System.out.println("play07() for() loop activated.");
     
    theTimeIsClip.start();
     
    Clip timeClip;
    File timeFile = new File("C:/PillMonitor/ProgramData/Audio/07.wav");
    AudioInputStream stream = AudioSystem.getAudioInputStream(timeFile);
    AudioFormat format = stream.getFormat();
    DataLine.Info infos = new DataLine.Info(Clip.class, format);
    timeClip = (Clip) AudioSystem.getLine(infos);
    timeClip.open(stream);
    timeClip.start();
     
    timeForClip.start();
     
    dexClip.start();
     
    andClip.start();
     
    hydClip.start();
     
    if(i != 0)
    	break;
     
    repeatClip.start();
    	}
    }
     
    private void play11() throws UnsupportedAudioFileException, LineUnavailableException, InterruptedException, IOException {
     
    for(int i = 0; i < 2; i++) {
     
    theTimeIsClip.start();
     
    Clip timeClip;
    File timeFile = new File("C:/PillMonitor/ProgramData/Audio/11.wav");
    AudioInputStream stream = AudioSystem.getAudioInputStream(timeFile);
    AudioFormat format = stream.getFormat();
    DataLine.Info infos = new DataLine.Info(Clip.class, format);
    timeClip = (Clip) AudioSystem.getLine(infos);
    timeClip.open(stream);
    timeClip.start();
     
    timeForClip.start();
     
    hydClip.start();
     
     
    if(i != 0)
    	break;
     
    repeatClip.start();
    	}
    }
     
    private void play15() throws UnsupportedAudioFileException, LineUnavailableException, InterruptedException, IOException {
     
    for(int i = 0; i < 2; i++) {
     
    theTimeIsClip.start();
     
    Clip timeClip;
    File timeFile = new File("C:/PillMonitor/ProgramData/Audio/15.wav");
    AudioInputStream stream = AudioSystem.getAudioInputStream(timeFile);
    AudioFormat format = stream.getFormat();
    DataLine.Info infos = new DataLine.Info(Clip.class, format);
    timeClip = (Clip) AudioSystem.getLine(infos);
    timeClip.open(stream);
    timeClip.start();
     
    timeForClip.start();
     
    hydClip.start();
     
    if(i != 0)
    	break;
     
    repeatClip.start();
    	}
    }
     
    private void play19() throws UnsupportedAudioFileException, LineUnavailableException, InterruptedException, IOException {
     
    for(int i = 0; i < 2; i++) {
     
    theTimeIsClip.start();
     
    Clip timeClip;
    File timeFile = new File("C:/PillMonitor/ProgramData/Audio/15.wav");
    AudioInputStream stream = AudioSystem.getAudioInputStream(timeFile);
    AudioFormat format = stream.getFormat();
    DataLine.Info infos = new DataLine.Info(Clip.class, format);
    timeClip = (Clip) AudioSystem.getLine(infos);
    timeClip.open(stream);
    timeClip.start();
     
    timeForClip.start();
     
    hydClip.start();
     
    andClip.start();
     
    gabClip.start();
     
    if(i != 0)
    	break;
     
    repeatClip.start();
    	}
    }
    }
     
    class WaitingMachine {
     
    public static int waitFor() {
     
    System.out.println("waitFor() called; while() loop activated.");
     
    while(Calendar.getInstance().get(Calendar.HOUR_OF_DAY) != 7 && Calendar.getInstance().get(Calendar.HOUR_OF_DAY) != 11 
     
    && Calendar.getInstance().get(Calendar.HOUR_OF_DAY) != 15 && Calendar.getInstance().get(Calendar.HOUR_OF_DAY) != 19 
     
    && Calendar.getInstance().get(Calendar.MILLISECOND) != 0) {
     
    continue;
    }
     
    System.out.println("while() loop break; returning hour to main()");
    Calendar calendar = Calendar.getInstance();
    return calendar.get(Calendar.HOUR_OF_DAY);
     
    }
     
     
     
    }
     
    public class PillMonitor {
     
    public static void main(String[] args) {
     
    System.out.println("Pill Monitor v1.0.  Do not close this window.");
     
    for(;;) {
    System.out.println("Main is now calling waitFor()");
    int pillTimer = WaitingMachine.waitFor();
    System.out.println("Now creating FilePlayer object.");
    FilePlayer player = new FilePlayer(pillTimer);
    System.out.println("Execution has returned to main; activating playAudio() method.");
    player.playAudio();
    }
     
    	}
    }

    -summit45

  4. #4
    Member
    Join Date
    Jul 2013
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Automatic audio file player not working

    Ok, I've got the loop problem fixed - the audio only plays once.

    My problem is now just this: In each method of the FilePlayer object, only the audio file that is initialized there actually plays. The others, that I set up in the static initialization block, simply don't play.

    -Summit45

    --- Update ---

    Yet another update... I have now got all the audio files playing by putting open() code in the initializer block. I also managed to tenatively keep it from looping through twice by adding a clause about 10 milliseconds in the while() block (can't run more than 10 milliseconds after the hour).

    The problem now is again - making it wait! It's playing all the clips at once, just as I feared. It needs to play each in order, and not move on until the first is done.

    My use of wait() threw an exception. How else does one do that?

    At this point maybe I can find the answer on Google. I'll try, but I'd appreciate an answer here anyway in case I fail.

    Thanks folks!
    -summit45

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Automatic audio file player not working

    Can you edit your post and properly format the code? All the statements should not start in the first column. Logically nested statements should be indented making the code easier to read.

    Instead of using a spinning loop in waitFor() why not use a Timer?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Automatic audio file player not working

    In addition to what Norm suggested...
    If you have further problems post the revised code so we are all looking at the same thing. Also (again) please copy-paste the code to preserve the indentation
    More detailed help can be found on the Announcements page

  7. #7
    Member
    Join Date
    Jul 2013
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Automatic audio file player not working

    Yeah, I'm sorry about the lack of indentation. I wrote it in Notepad and didn't personally care about indenting, but it's not fair to ask others to pick through that mess. Here is the corrected version, this is the code as it stands now (I turned off WordWrap because I'm not sure if Java can continue reading over multiple lines in some cases, so some lines may be a little long):

    import javax.sound.sampled.*;
    import java.util.Calendar;
    import java.io.File;
    import java.io.IOException;
     
    class FilePlayer { 
     
    	private static File theTimeIsFile, timeForFile, repeatFile, dexFile, hydFile, gabFile, andFile;
    	private static AudioInputStream theTimeIsStream, timeForStream, repeatStream, dexStream, hydStream, gabStream, andStream;
    	private static Clip theTimeIsClip, timeForClip, repeatClip, dexClip, hydClip, gabClip, andClip;
    	private static AudioFormat theTimeIsFormat, timeForFormat, repeatFormat, dexFormat, hydFormat, gabFormat, andFormat;
    	private static DataLine.Info theTimeIsInfo, timeForInfo, repeatInfo, dexInfo, hydInfo, gabInfo, andInfo;
    	private int time;
     
    static {
     
     
    	theTimeIsFile = new File("C:/PillMonitor/ProgramData/Audio/TheTimeIs.wav");
    	timeForFile = new File("C:/PillMonitor/ProgramData/Audio/TimeFor.wav");
    	repeatFile = new File("C:/PillMonitor/ProgramData/Audio/Repeat.wav");
    	dexFile = new File("C:/PillMonitor/ProgramData/Audio/dex.wav");
    	hydFile = new File("C:/PillMonitor/ProgramData/Audio/hyd.wav");
    	gabFile = new File("C:/PillMonitor/ProgramData/Audio/gab.wav");
    	andFile = new File("C:/PillMonitor/ProgramData/Audio/and.wav");
     
    try {
     
    	theTimeIsStream = AudioSystem.getAudioInputStream(theTimeIsFile);
    	timeForStream = AudioSystem.getAudioInputStream(timeForFile);
    	repeatStream = AudioSystem.getAudioInputStream(repeatFile);
    	dexStream = AudioSystem.getAudioInputStream(dexFile);
    	hydStream = AudioSystem.getAudioInputStream(hydFile);
    	gabStream = AudioSystem.getAudioInputStream(gabFile);
    	andStream = AudioSystem.getAudioInputStream(andFile);
    } 
    	catch(UnsupportedAudioFileException ex) {
    		System.out.println("Audio files are unsupported.");
    		System.exit(1);
    } 	catch(IOException ex) {
    		System.out.println("IO Exception in FilePlayer SIB, AudioStream initialization.");
    		System.exit(1);
    }
     
    	theTimeIsFormat = theTimeIsStream.getFormat();
    	timeForFormat = timeForStream.getFormat();
    	repeatFormat = repeatStream.getFormat();
    	dexFormat  = dexStream.getFormat();
    	hydFormat = hydStream.getFormat();
    	gabFormat = gabStream.getFormat();
    	andFormat = andStream.getFormat();
     
    	theTimeIsInfo = new DataLine.Info(Clip.class, theTimeIsFormat);
    	timeForInfo = new DataLine.Info(Clip.class, timeForFormat);
    	repeatInfo = new DataLine.Info(Clip.class, repeatFormat);
    	dexInfo = new DataLine.Info(Clip.class, dexFormat);
    	hydInfo = new DataLine.Info(Clip.class, hydFormat);
    	gabInfo = new DataLine.Info(Clip.class, gabFormat);
    	andInfo = new DataLine.Info(Clip.class, andFormat);
     
    try {
     
    	theTimeIsClip = (Clip) AudioSystem.getLine(theTimeIsInfo);
    	timeForClip = (Clip) AudioSystem.getLine(timeForInfo);
    	repeatClip = (Clip) AudioSystem.getLine(repeatInfo);
    	dexClip = (Clip) AudioSystem.getLine(dexInfo);
    	hydClip = (Clip) AudioSystem.getLine(hydInfo);
    	gabClip = (Clip) AudioSystem.getLine(gabInfo);
    	andClip = (Clip) AudioSystem.getLine(andInfo);
    } 
    	catch(LineUnavailableException ex) {
    		System.out.println("Audio line unavailable exception in FilePlayer static initialization block.");
    		System.exit(1);
     
    }
     
    try {
     
    	theTimeIsClip.open(theTimeIsStream);
    	timeForClip.open(timeForStream);
    	repeatClip.open(repeatStream);
    	dexClip.open(dexStream);
    	hydClip.open(hydStream);
    	gabClip.open(gabStream);
    	andClip.open(andStream);
    } 
    	catch(LineUnavailableException ex) {
    		System.out.println("LU-Ex in FilePlayer static-init-block opening methods.");
    		System.exit(1);
    }
    	catch(IOException ex) {
    		System.out.println("IOEx in FilePlayer static-init-block opening methods.");
    		System.exit(1);
    }
    }
     
    public FilePlayer(int time) {
    	System.out.println("FilePlayer constructor invoked successfully.");
    	this.time = time;
     
    	System.out.println("FilePlayer construction complete.");
    	}
     
    public void playAudio() {
     
    	System.out.println("playAudio() method invoked successfully.  Function falling into switch() block.");
     
    	switch(time) {
     
    		case 7: try {play07();}
    		             catch(IOException ex) {System.out.println("IOEx in FP switchblock (method play07())."); System.exit(1);}
    		             catch(UnsupportedAudioFileException ex) {System.out.println("USAF-Ex in FP switch method 07."); System.exit(1);}
    		             catch(LineUnavailableException ex) {System.out.println("LU-Ex FP SB m-7."); System.exit(1);}
    		             catch(InterruptedException ex) {System.out.println("INT-Ex FP SB m-7."); System.exit(1);}
    		             break;
    		case 11: try {play11();}
    		             catch(IOException ex) {System.out.println("IOEx in FP switchblock (method play11())."); System.exit(1);}
    		             catch(UnsupportedAudioFileException ex) {System.out.println("USAF-Ex in FP switch method 11."); System.exit(1);}
    		             catch(LineUnavailableException ex) {System.out.println("LU-Ex FP SB m-11."); System.exit(1);}
    		             catch(InterruptedException ex) {System.out.println("INT-Ex FP SB m-11."); System.exit(1);}
    		             break;
    		case 15: try {play15();}
    		              catch(IOException ex) {System.out.println("IOEx in FP switchblock (method play15())."); System.exit(1);}
    		              catch(UnsupportedAudioFileException ex) {System.out.println("USAF-Ex in FP switch method 15."); System.exit(1);}
    		              catch(LineUnavailableException ex) {System.out.println("LU-Ex FP SB m-15."); System.exit(1);}
    		              catch(InterruptedException ex) {System.out.println("INT-Ex FP SB m-15."); System.exit(1);}
    		              break;
    		case 19: try {play19();}
    		             catch(IOException ex) {System.out.println("IOEx in FP switchblock (method play19())."); System.exit(1);}
    		             catch(UnsupportedAudioFileException ex) {System.out.println("USAF-Ex in FP switch method 19."); System.exit(1);}
    		             catch(LineUnavailableException ex) {System.out.println("LU-Ex FP SB m-19."); System.exit(1);}
    		             catch(InterruptedException ex) {System.out.println("INT-Ex FP SB m-19."); System.exit(1);}
    		             break;
    		}
     
    	}
     
    private void play07() throws UnsupportedAudioFileException, LineUnavailableException, InterruptedException, IOException {
     
    	System.out.println("Function passed to play07().");
     
    		for(int i = 0; i < 2; i++) {
     
    		System.out.println("play07() for() loop activated.");
     
    		theTimeIsClip.start();
     
    		Clip timeClip;
    		File timeFile = new File("C:/PillMonitor/ProgramData/Audio/07.wav");
    		AudioInputStream stream = AudioSystem.getAudioInputStream(timeFile);
    		AudioFormat format = stream.getFormat();
    		DataLine.Info infos = new DataLine.Info(Clip.class, format);
    		timeClip = (Clip) AudioSystem.getLine(infos);
    		timeClip.open(stream);
    		timeClip.start();
     
    		timeForClip.start();
     
    		dexClip.start();
     
    		andClip.start();
     
    		hydClip.start();
     
    		if(i != 0)
    		break;
     
    		repeatClip.start();
    		}
    	}
     
    private void play11() throws UnsupportedAudioFileException, LineUnavailableException, InterruptedException, IOException {
     
    	for(int i = 0; i < 2; i++) {
     
    		theTimeIsClip.start();
     
    		Clip timeClip;
    		File timeFile = new File("C:/PillMonitor/ProgramData/Audio/11.wav");
    		AudioInputStream stream = AudioSystem.getAudioInputStream(timeFile);
    		AudioFormat format = stream.getFormat();
    		DataLine.Info infos = new DataLine.Info(Clip.class, format);
    		timeClip = (Clip) AudioSystem.getLine(infos);
    		timeClip.open(stream);
    		timeClip.start();
     
    		timeForClip.start();
     
    		hydClip.start();
     
     
    		if(i != 0)
    		break;
     
    		repeatClip.start();
    		}
    	}
     
    private void play15() throws UnsupportedAudioFileException, LineUnavailableException, InterruptedException, IOException {
     
    	for(int i = 0; i < 2; i++) {
     
    		theTimeIsClip.start();
     
    		Clip timeClip;
    		File timeFile = new File("C:/PillMonitor/ProgramData/Audio/15.wav");
    		AudioInputStream stream = AudioSystem.getAudioInputStream(timeFile);
    		AudioFormat format = stream.getFormat();
    		DataLine.Info infos = new DataLine.Info(Clip.class, format);
    		timeClip = (Clip) AudioSystem.getLine(infos);
    		timeClip.open(stream);
    		timeClip.start();
     
    		timeForClip.start();
     
    		hydClip.start();
     
    		if(i != 0)
    		break;
     
    		repeatClip.start();
    	}
    }
     
    private void play19() throws UnsupportedAudioFileException, LineUnavailableException, InterruptedException, IOException {
     
    	for(int i = 0; i < 2; i++) {
     
    		theTimeIsClip.start();
     
    		Clip timeClip;
    		File timeFile = new File("C:/PillMonitor/ProgramData/Audio/15.wav");
    		AudioInputStream stream = AudioSystem.getAudioInputStream(timeFile);
    		AudioFormat format = stream.getFormat();
    		DataLine.Info infos = new DataLine.Info(Clip.class, format);
    		timeClip = (Clip) AudioSystem.getLine(infos);
    		timeClip.open(stream);
    		timeClip.start();
     
    		timeForClip.start();
     
    		hydClip.start();
     
    		andClip.start();
     
    		gabClip.start();
     
    		if(i != 0)
    		break;
     
    		repeatClip.start();
    	}
    }
    }
     
    class WaitingMachine {
     
    public static int waitFor() {
     
    	System.out.println("waitFor() called; while() loop activated.");
     
    		while(Calendar.getInstance().get(Calendar.HOUR_OF_DAY) != 7 && Calendar.getInstance().get(Calendar.HOUR_OF_DAY) != 11 && Calendar.getInstance().get(Calendar.HOUR_OF_DAY) != 15 && Calendar.getInstance().get(Calendar.HOUR_OF_DAY) != 19 || Calendar.getInstance().get(Calendar.SECOND) != 0 || Calendar.getInstance().get(Calendar.MINUTE) != 0 || Calendar.getInstance().get(Calendar.MILLISECOND) > 10) {
    			continue;
    		}
     
    	System.out.println("while() loop break; returning hour to main()");
    	Calendar calendar = Calendar.getInstance();
    	return calendar.get(Calendar.HOUR_OF_DAY);
     
    	}
     
     
     
    }
     
    public class PillMonitor {
     
    public static void main(String[] args) {
     
    	System.out.println("Pill Monitor v1.0.  Do not close this window.");
     
    		for(;;) {
    		System.out.println("Main is now calling waitFor()");
    		int pillTimer = WaitingMachine.waitFor();
    		System.out.println("Now creating FilePlayer object.");
    		FilePlayer player = new FilePlayer(pillTimer);
    		System.out.println("Execution has returned to main; activating playAudio() method.");
    		player.playAudio();
    		}
     
    	}
    }

    -summit45

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Automatic audio file player not working

    Can you explain what the waitFor() method is supposed to do?

    Using a loop to wait is VERY POOR technique. A better way would be to compute how long to wait and use the Thread class's sleep() method.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Jul 2013
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Automatic audio file player not working

    Quote Originally Posted by Norm View Post
    Can you explain what the waitFor() method is supposed to do?

    Using a loop to wait is VERY POOR technique. A better way would be to compute how long to wait and use the Thread class's sleep() method.
    I understand that. When I wrote it, I figured it was probably rather disgusting code-wise, but again, I am inexperienced, but I figure the best way to learn is to go do it, even if it isn't perfect the first time.

    The while() loop was the best thing I could think of at the time because I didn't know what else to use. All it does is check on the hour of the day through Calendar.getInstance().get(Calendar.HOUR_OF_DAY) and it keeps looping (monitoring the time) while it's NOT 7, 11, 15, or 19. At those times, it also checks the seconds, minutes, and milliseconds (because it's only supposed to break and run the code once - at x:00.000.

    When it hits a target time, the loop breaks, and the time is returned to main(), into the variable assignment that it was called for. That is then used to construct a FilePlayer object which is supposed to play a different sequence of .wav files based on the time, but right now, they're all playing at once because I don't know what code to use after each invocation of start() for the clips to halt execution until the full file has played.

    -summit45

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Automatic audio file player not working

    Is this what the waitFor() method is supposed to do:
    loop until the time is one of these values: 0700, 1100, 1500 or 1900
    When the time matches one of those, return the value matched.

    Have you tested the method by itself to see if it returns at those times and no others?

    they're all playing at once
    Have you tried debugging the code by adding println statements to see why it tries to play more than one sound at a time?

    How have you tested the FilePlayer class and its methods? For example make a loop that makes an instance and calls the method with the next time value and uses the Thread sleep() method to wait a few seconds between each call:
    begin loop
    call player method with next time value
    sleep 30 seconds
    end loop
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Member
    Join Date
    Jul 2013
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Automatic audio file player not working

    println()'s would show me what's happening and when, but not why - and indeed as the code stands now, they already DO show that the for() loop in the FilePlayer is being called twice, one time immediately after the other with no delay.

    Just to be clear: Are you saying that when a clip's start() method is called, execution is not supposed to continue until that clip is finished? Because I saw nothing to indicate that in the API or tutorials.

    -summit45

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Automatic audio file player not working

    The println()s would help you understand where the code is executed and what the values or variables are when the code is execute. The println()s in the current code need to print out the values of the variables that the code uses.
    clip's start() method is called,
    Add println()s before and after the call to the method that print out the time. The value returned by
    System.currentTimeMillis() is useful. The printout will show you how long the method took when it executed.

    The waitFor() method needs to be replaced. Use some logic to compute the duration needed to wait and use the Thread class's sleep() method to wait until the desired time arrives.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Member
    Join Date
    Jul 2013
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Automatic audio file player not working

    Does start() normally finish playing the audio file it references before allowing execution to continue?

    -summit45

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Automatic audio file player not working

    Does start() normally finish playing the audio file it references before allowing execution to continue?
    I don't know. The name: start indicates to me that it starts the playing and returns immediately without waiting for completion.
    Print the time before the call and after the call to see.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Member
    Join Date
    Jul 2013
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Automatic audio file player not working

    Well, the program works now. Doesn't do quite everything I'd like, but it's good enough, it runs, it will get the job done I believe.

    I thank everyone who replied for their help!

    -summit45

    --- Update ---

    Here's the final code, if it peaks anyone's curiosity:

    import javax.sound.sampled.*;
    import java.util.Calendar;
    import java.io.File;
    import java.io.IOException;
    import java.math.*;
    import java.io.IOException;
     
    class FilePlayer { 
     
    	private static File theTimeIsFile, timeForFile, repeatFile, dexFile, hydFile, gabFile, andFile;
    	private static AudioInputStream theTimeIsStream, timeForStream, repeatStream, dexStream, hydStream, gabStream, andStream;
    	private static Clip theTimeIsClip, timeForClip, repeatClip, dexClip, hydClip, gabClip, andClip;
    	private static AudioFormat theTimeIsFormat, timeForFormat, repeatFormat, dexFormat, hydFormat, gabFormat, andFormat;
    	private static DataLine.Info theTimeIsInfo, timeForInfo, repeatInfo, dexInfo, hydInfo, gabInfo, andInfo;
    	private int time;
     
    static {
     
     
    	theTimeIsFile = new File("C:/PillMonitor/ProgramData/Audio/TheTimeIs.wav");
    	timeForFile = new File("C:/PillMonitor/ProgramData/Audio/TimeFor.wav");
    	repeatFile = new File("C:/PillMonitor/ProgramData/Audio/Repeat.wav");
    	dexFile = new File("C:/PillMonitor/ProgramData/Audio/dex.wav");
    	hydFile = new File("C:/PillMonitor/ProgramData/Audio/hyd.wav");
    	gabFile = new File("C:/PillMonitor/ProgramData/Audio/gab.wav");
    	andFile = new File("C:/PillMonitor/ProgramData/Audio/and.wav");
     
    try {
     
    	theTimeIsStream = AudioSystem.getAudioInputStream(theTimeIsFile);
    	timeForStream = AudioSystem.getAudioInputStream(timeForFile);
    	repeatStream = AudioSystem.getAudioInputStream(repeatFile);
    	dexStream = AudioSystem.getAudioInputStream(dexFile);
    	hydStream = AudioSystem.getAudioInputStream(hydFile);
    	gabStream = AudioSystem.getAudioInputStream(gabFile);
    	andStream = AudioSystem.getAudioInputStream(andFile);
    } 
    	catch(UnsupportedAudioFileException ex) {
    		System.out.println("Audio files are unsupported.");
    		System.exit(1);
    } 	catch(IOException ex) {
    		System.out.println("IO Exception in FilePlayer SIB, AudioStream initialization.");
    		System.exit(1);
    }
     
    	theTimeIsFormat = theTimeIsStream.getFormat();
    	timeForFormat = timeForStream.getFormat();
    	repeatFormat = repeatStream.getFormat();
    	dexFormat  = dexStream.getFormat();
    	hydFormat = hydStream.getFormat();
    	gabFormat = gabStream.getFormat();
    	andFormat = andStream.getFormat();
     
    	theTimeIsInfo = new DataLine.Info(Clip.class, theTimeIsFormat);
    	timeForInfo = new DataLine.Info(Clip.class, timeForFormat);
    	repeatInfo = new DataLine.Info(Clip.class, repeatFormat);
    	dexInfo = new DataLine.Info(Clip.class, dexFormat);
    	hydInfo = new DataLine.Info(Clip.class, hydFormat);
    	gabInfo = new DataLine.Info(Clip.class, gabFormat);
    	andInfo = new DataLine.Info(Clip.class, andFormat);
     
    try {
     
    	theTimeIsClip = (Clip) AudioSystem.getLine(theTimeIsInfo);
    	timeForClip = (Clip) AudioSystem.getLine(timeForInfo);
    	repeatClip = (Clip) AudioSystem.getLine(repeatInfo);
    	dexClip = (Clip) AudioSystem.getLine(dexInfo);
    	hydClip = (Clip) AudioSystem.getLine(hydInfo);
    	gabClip = (Clip) AudioSystem.getLine(gabInfo);
    	andClip = (Clip) AudioSystem.getLine(andInfo);
    } 
    	catch(LineUnavailableException ex) {
    		System.out.println("Audio line unavailable exception in FilePlayer static initialization block.");
    		System.exit(1);
     
    }
     
    try {
     
    	theTimeIsClip.open(theTimeIsStream);
    	timeForClip.open(timeForStream);
    	repeatClip.open(repeatStream);
    	dexClip.open(dexStream);
    	hydClip.open(hydStream);
    	gabClip.open(gabStream);
    	andClip.open(andStream);
    } 
    	catch(LineUnavailableException ex) {
    		System.out.println("LU-Ex in FilePlayer static-init-block opening methods.");
    		System.exit(1);
    }
    	catch(IOException ex) {
    		System.out.println("IOEx in FilePlayer static-init-block opening methods.");
    		System.exit(1);
    }
    }
     
    private static double theTimeIsTimeVar, timeForTimeVar, repeatTimeVar, dexTimeVar, hydTimeVar, gabTimeVar, andTimeVar;
    private static long theTimeIsTime, timeForTime, repeatTime, dexTime, hydTime, gabTime, andTime;
     
    static {
     
    theTimeIsTimeVar = theTimeIsClip.getMicrosecondLength() * 0.001;
    timeForTimeVar =  timeForClip.getMicrosecondLength() * 0.001;
    repeatTimeVar =   repeatClip.getMicrosecondLength() * 0.001;
    dexTimeVar =  dexClip.getMicrosecondLength() * 0.001;
    hydTimeVar =  hydClip.getMicrosecondLength() * 0.001;
    gabTimeVar = gabClip.getMicrosecondLength() * 0.001;
    andTimeVar = andClip.getMicrosecondLength() * 0.001;
     
    BigDecimal theTimeIsBD = new BigDecimal(theTimeIsTimeVar);
    BigDecimal timeForBD = new BigDecimal(timeForTimeVar);
    BigDecimal repeatBD = new BigDecimal(repeatTimeVar);
    BigDecimal dexBD = new BigDecimal(dexTimeVar);
    BigDecimal hydBD = new BigDecimal(hydTimeVar);
    BigDecimal gabBD = new BigDecimal(gabTimeVar);
    BigDecimal andBD = new BigDecimal(andTimeVar);
     
    theTimeIsTime = theTimeIsBD.longValue();
    timeForTime = timeForBD.longValue();
    repeatTime = repeatBD.longValue();
    dexTime = dexBD.longValue();
    hydTime = hydBD.longValue();
    gabTime = gabBD.longValue();
    andTime = andBD.longValue();
    }
     
    public FilePlayer(int time) {
     
    	this.time = time;
     
    	}
     
    public void playAudio() {
     
     
    	switch(time) {
     
    		case 7: try {play07();}
    		             catch(IOException ex) {System.out.println("IOEx in FP switchblock (method play07())."); System.exit(1);}
    		             catch(UnsupportedAudioFileException ex) {System.out.println("USAF-Ex in FP switch method 07."); System.exit(1);}
    		             catch(LineUnavailableException ex) {System.out.println("LU-Ex FP SB m-7."); System.exit(1);}
    		             catch(InterruptedException ex) {System.out.println("INT-Ex FP SB m-7."); System.exit(1);}
    		             break;
    		case 11: try {play11();}
    		             catch(IOException ex) {System.out.println("IOEx in FP switchblock (method play11())."); System.exit(1);}
    		             catch(UnsupportedAudioFileException ex) {System.out.println("USAF-Ex in FP switch method 11."); System.exit(1);}
    		             catch(LineUnavailableException ex) {System.out.println("LU-Ex FP SB m-11."); System.exit(1);}
    		             catch(InterruptedException ex) {System.out.println("INT-Ex FP SB m-11."); System.exit(1);}
    		             break;
    		case 15: try {play15();}
    		              catch(IOException ex) {System.out.println("IOEx in FP switchblock (method play15())."); System.exit(1);}
    		              catch(UnsupportedAudioFileException ex) {System.out.println("USAF-Ex in FP switch method 15."); System.exit(1);}
    		              catch(LineUnavailableException ex) {System.out.println("LU-Ex FP SB m-15."); System.exit(1);}
    		              catch(InterruptedException ex) {System.out.println("INT-Ex FP SB m-15."); System.exit(1);}
    		              break;
    		case 19: try {play19();}
    		             catch(IOException ex) {System.out.println("IOEx in FP switchblock (method play19())."); System.exit(1);}
    		             catch(UnsupportedAudioFileException ex) {System.out.println("USAF-Ex in FP switch method 19."); System.exit(1);}
    		             catch(LineUnavailableException ex) {System.out.println("LU-Ex FP SB m-19."); System.exit(1);}
    		             catch(InterruptedException ex) {System.out.println("INT-Ex FP SB m-19."); System.exit(1);}
    		             break;
    		}
     
    	}
     
    private void play07() throws UnsupportedAudioFileException, LineUnavailableException, InterruptedException, IOException {
     
     
    		for(int i = 0; i < 2; i++) {
     
     
    		theTimeIsClip.start();
    		Thread.currentThread().sleep(theTimeIsTime);
    		theTimeIsClip.stop();
    		theTimeIsClip.setFramePosition(0);
     
    		Clip timeClip;
    		File timeFile = new File("C:/PillMonitor/ProgramData/Audio/07.wav");
    		AudioInputStream stream = AudioSystem.getAudioInputStream(timeFile);
    		AudioFormat format = stream.getFormat();
    		DataLine.Info infos = new DataLine.Info(Clip.class, format);
    		timeClip = (Clip) AudioSystem.getLine(infos);
    		timeClip.open(stream);
    		double timeTimeVar = timeClip.getMicrosecondLength() * 0.001;
    		BigDecimal timeTimeBD = new BigDecimal(timeTimeVar);	
    		long timeTime = timeTimeBD.longValue();
    		timeClip.start();
    		Thread.currentThread().sleep(timeTime);
    		timeClip.stop();
    		timeClip.setFramePosition(0);
     
    		timeForClip.start();
    		Thread.currentThread().sleep(timeForTime);
    		timeForClip.stop();
    		timeForClip.setFramePosition(0);
     
    		dexClip.start();
    		Thread.currentThread().sleep(dexTime);
    		dexClip.stop();
    		dexClip.setFramePosition(0);
     
    		andClip.start();
    		Thread.currentThread().sleep(dexTime);
    		andClip.stop();
    		andClip.setFramePosition(0);
     
    		hydClip.start();
    		Thread.currentThread().sleep(dexTime);
    		hydClip.stop();
    		hydClip.setFramePosition(0);
     
    		if(i != 0) {
    		break;
    		}
     
    		repeatClip.start();
    		Thread.currentThread().sleep(repeatTime);
    		repeatClip.stop();
    		repeatClip.setFramePosition(0);
    		}
    	}
     
    private void play11() throws UnsupportedAudioFileException, LineUnavailableException, InterruptedException, IOException {
     
    	for(int i = 0; i < 2; i++) {
     
    		theTimeIsClip.start();
     
    		Thread.currentThread().sleep(theTimeIsTime);
    		theTimeIsClip.stop();
    		theTimeIsClip.setFramePosition(0);
     
    		Clip timeClip;
    		File timeFile = new File("C:/PillMonitor/ProgramData/Audio/11.wav");
    		AudioInputStream stream = AudioSystem.getAudioInputStream(timeFile);
    		AudioFormat format = stream.getFormat();
    		DataLine.Info infos = new DataLine.Info(Clip.class, format);
    		timeClip = (Clip) AudioSystem.getLine(infos);
    		timeClip.open(stream);
    		double timeTimeVar = timeClip.getMicrosecondLength() * 0.001;
    		BigDecimal timeTimeBD = new BigDecimal(timeTimeVar);	
    		long timeTime = timeTimeBD.longValue();
    		timeClip.start();
    		Thread.currentThread().sleep(timeTime);
    		timeClip.stop();
    		timeClip.setFramePosition(0);
     
    		timeForClip.start();
    		Thread.currentThread().sleep(timeForTime);
    		timeForClip.stop();
    		timeForClip.setFramePosition(0);
     
    		hydClip.start();
    		Thread.currentThread().sleep(hydTime);
    		hydClip.stop();
    		hydClip.setFramePosition(0);
     
     
    		if(i != 0)
    		break;
     
    		repeatClip.start();
    		Thread.currentThread().sleep(repeatTime);
    		repeatClip.stop();
    		repeatClip.setFramePosition(0);
    		}
    	}
     
    private void play15() throws UnsupportedAudioFileException, LineUnavailableException, InterruptedException, IOException {
     
    	for(int i = 0; i < 2; i++) {
     
    		theTimeIsClip.start();
    		Thread.currentThread().sleep(theTimeIsTime);
    		theTimeIsClip.stop();
    		theTimeIsClip.setFramePosition(0);
     
    		Clip timeClip;
    		File timeFile = new File("C:/PillMonitor/ProgramData/Audio/15.wav");
    		AudioInputStream stream = AudioSystem.getAudioInputStream(timeFile);
    		AudioFormat format = stream.getFormat();
    		DataLine.Info infos = new DataLine.Info(Clip.class, format);
    		timeClip = (Clip) AudioSystem.getLine(infos);
    		timeClip.open(stream);
    		double timeTimeVar = timeClip.getMicrosecondLength() * 0.001;
    		BigDecimal timeTimeBD = new BigDecimal(timeTimeVar);	
    		long timeTime = timeTimeBD.longValue();
    		timeClip.start();
    		Thread.currentThread().sleep(timeTime);
    		timeClip.stop();
    		timeClip.setFramePosition(0);
     
    		timeForClip.start();
    		Thread.currentThread().sleep(timeForTime);
    		timeForClip.stop();
    		timeForClip.setFramePosition(0);
     
    		hydClip.start();
    		Thread.currentThread().sleep(hydTime);
    		hydClip.stop();
    		hydClip.setFramePosition(0);
     
    		if(i != 0)
    		break;
     
    		repeatClip.start();
    		Thread.currentThread().sleep(repeatTime);
    		repeatClip.stop();
    		repeatClip.setFramePosition(0);
    	}
    }
     
    private void play19() throws UnsupportedAudioFileException, LineUnavailableException, InterruptedException, IOException {
     
    	for(int i = 0; i < 2; i++) {
     
    		theTimeIsClip.start();
    		Thread.currentThread().sleep(theTimeIsTime);
    		theTimeIsClip.stop();
    		theTimeIsClip.setFramePosition(0);
     
    		Clip timeClip;
    		File timeFile = new File("C:/PillMonitor/ProgramData/Audio/19.wav");
    		AudioInputStream stream = AudioSystem.getAudioInputStream(timeFile);
    		AudioFormat format = stream.getFormat();
    		DataLine.Info infos = new DataLine.Info(Clip.class, format);
    		timeClip = (Clip) AudioSystem.getLine(infos);
    		timeClip.open(stream);
    		double timeTimeVar = timeClip.getMicrosecondLength() * 0.001;
    		BigDecimal timeTimeBD = new BigDecimal(timeTimeVar);	
    		long timeTime = timeTimeBD.longValue();
    		timeClip.start();
    		Thread.currentThread().sleep(timeTime);
    		timeClip.stop();
    		timeClip.setFramePosition(0);
     
    		timeForClip.start();
    		Thread.currentThread().sleep(timeForTime);
    		timeForClip.stop();
    		timeForClip.setFramePosition(0);
     
    		hydClip.start();
    		Thread.currentThread().sleep(hydTime);
    		hydClip.stop();
    		hydClip.setFramePosition(0);
     
    		andClip.start();
    		Thread.currentThread().sleep(andTime);
    		andClip.stop();
    		andClip.setFramePosition(0);
     
    		gabClip.start();
    		Thread.currentThread().sleep(gabTime);
    		gabClip.stop();
    		gabClip.setFramePosition(0);
     
    		if(i != 0)
    		break;
     
    		repeatClip.start();
    		Thread.currentThread().sleep(repeatTime);
    		repeatClip.stop();
    		repeatClip.setFramePosition(0);
    	}
    }
    }
     
    class WaitingMachine {
     
    public static int waitFor() {
     
    		while(Calendar.getInstance().get(Calendar.HOUR_OF_DAY) != 7 && Calendar.getInstance().get(Calendar.HOUR_OF_DAY) != 11 && Calendar.getInstance().get(Calendar.HOUR_OF_DAY) != 15 && Calendar.getInstance().get(Calendar.HOUR_OF_DAY) != 19 || Calendar.getInstance().get(Calendar.SECOND) != 0 || Calendar.getInstance().get(Calendar.MINUTE) != 0 || Calendar.getInstance().get(Calendar.MILLISECOND) > 10) {
    			continue;
    		}
     
    	Calendar calendar = Calendar.getInstance();
    	return calendar.get(Calendar.HOUR_OF_DAY);
     
    	}
     
     
     
    }
     
    public class PillMonitor {
     
    public static void main(String[] args) {
     
    	System.out.println("Pill Monitor v1.0.  Do not close this window.");
     
    		for(;;) {
    		int pillTimer = WaitingMachine.waitFor();
    		new Watcher(pillTimer).start();
    		FilePlayer player = new FilePlayer(pillTimer);
    		player.playAudio();
    		}
     
    	}
     
    }
     
    class Watcher extends Thread{
     
    private int hour;
    private static String[] pills;
     
    static {
    pills = new String[20];
     
    pills[7] = "Dexa and Hydro";
    pills[11] = "Hydro";
    pills[15] = "Hydro";
    pills[19] = "Hydro and Gaba";
     
    for(int i = 0; i < pills.length; i++) {
     
    if(i != 7 && i != 11 && i != 15 && i != 19)
    	pills[i] = null;
    	}
    }
     
    public Watcher(int hour) {
     
    	this.hour = hour;
    }
     
     
    @Override
    public void run() {
    	if(hour == 15)
    		hour = 3;
    	else if(hour == 19)
    		hour = 7;
     
    	System.out.printf("\nLast pill: %s          Time: %d", pills[hour], hour);
    	System.out.print(":00");
    	if(hour == 7 || hour == 11 )
    		System.out.print(" AM");
    	else
    		System.out.print(" PM");
    	try {
    		System.in.read();
    	} catch(IOException ex) {
    		System.out.println("IOException in thread \"Watcher.\"");
    	}
    	System.out.print("\t-Pill taken\n");
     
    	}
     
    }

    -summit45

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Automatic audio file player not working

    The waitFor() method needs to be rewritten. The long looping while loop is a terrible way to wait for an event.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Member
    Join Date
    Jul 2013
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Automatic audio file player not working

    Quote Originally Posted by Norm View Post
    The waitFor() method needs to be rewritten. The long looping while loop is a terrible way to wait for an event.
    How would you do it? Like I said, I know most of the code I write could be improved. That's because I'm quite new to Java and teaching it to myself. I have no idea how I would compute the time to wait any other way. Of course if the program was started EXACTLY at one of the times, sure, just have it sleep 4 hours, then wake up, return, come back - and check for seconds to make sure it doesn't execute twice. But what if it's started at an odd time, like 1:37 PM? The next time to execute would be 3:00 PM, so we have to sleep for only 2 hours and 23 minutes. But then with this code you have to find the hour, and then somehow index that to the minutes and calculate the time to wait - yeah, complicated.

    That, versus a while() loop that just cycles and watches for the time to pop up. I don't see what's so terrible. It's just a little loop cycling over and over. Sure, it's not pretty, but it's not like it's going to overload the memory or something, just to loop watching a Calendar until a certain time.

    The thing is, I just accomplished what for more experienced programmers here is next to nothing I'm sure, but for me, just learning this, I learned and put to use a ton of new information. It doesn't surprise me that it's not 100% exactly perfect, but I'm pretty happy with the fact that it does EXACTLY what I want.

    Speaking of which, I did alter the code since last night, because I found a way to make it do all of what I wanted it to. So here is the ACTUAL final code:

    import javax.sound.sampled.*;
    import java.util.Calendar;
    import java.io.File;
    import java.io.IOException;
    import java.math.*;
    import java.io.IOException;
    import java.util.Scanner;
     
    class FilePlayer { 
     
    	private static File theTimeIsFile, timeForFile, repeatFile, dexFile, hydFile, gabFile, andFile;
    	private static AudioInputStream theTimeIsStream, timeForStream, repeatStream, dexStream, hydStream, gabStream, andStream;
    	private static Clip theTimeIsClip, timeForClip, repeatClip, dexClip, hydClip, gabClip, andClip;
    	private static AudioFormat theTimeIsFormat, timeForFormat, repeatFormat, dexFormat, hydFormat, gabFormat, andFormat;
    	private static DataLine.Info theTimeIsInfo, timeForInfo, repeatInfo, dexInfo, hydInfo, gabInfo, andInfo;
    	private int time;
     
    static {
     
     
    	theTimeIsFile = new File("C:/PillMonitor/ProgramData/Audio/TheTimeIs.wav");
    	timeForFile = new File("C:/PillMonitor/ProgramData/Audio/TimeFor.wav");
    	repeatFile = new File("C:/PillMonitor/ProgramData/Audio/Repeat.wav");
    	dexFile = new File("C:/PillMonitor/ProgramData/Audio/dex.wav");
    	hydFile = new File("C:/PillMonitor/ProgramData/Audio/hyd.wav");
    	gabFile = new File("C:/PillMonitor/ProgramData/Audio/gab.wav");
    	andFile = new File("C:/PillMonitor/ProgramData/Audio/and.wav");
     
    try {
     
    	theTimeIsStream = AudioSystem.getAudioInputStream(theTimeIsFile);
    	timeForStream = AudioSystem.getAudioInputStream(timeForFile);
    	repeatStream = AudioSystem.getAudioInputStream(repeatFile);
    	dexStream = AudioSystem.getAudioInputStream(dexFile);
    	hydStream = AudioSystem.getAudioInputStream(hydFile);
    	gabStream = AudioSystem.getAudioInputStream(gabFile);
    	andStream = AudioSystem.getAudioInputStream(andFile);
    } 
    	catch(UnsupportedAudioFileException ex) {
    		System.out.println("Audio files are unsupported.");
    		System.exit(1);
    } 	catch(IOException ex) {
    		System.out.println("IO Exception in FilePlayer SIB, AudioStream initialization.");
    		System.exit(1);
    }
     
    	theTimeIsFormat = theTimeIsStream.getFormat();
    	timeForFormat = timeForStream.getFormat();
    	repeatFormat = repeatStream.getFormat();
    	dexFormat  = dexStream.getFormat();
    	hydFormat = hydStream.getFormat();
    	gabFormat = gabStream.getFormat();
    	andFormat = andStream.getFormat();
     
    	theTimeIsInfo = new DataLine.Info(Clip.class, theTimeIsFormat);
    	timeForInfo = new DataLine.Info(Clip.class, timeForFormat);
    	repeatInfo = new DataLine.Info(Clip.class, repeatFormat);
    	dexInfo = new DataLine.Info(Clip.class, dexFormat);
    	hydInfo = new DataLine.Info(Clip.class, hydFormat);
    	gabInfo = new DataLine.Info(Clip.class, gabFormat);
    	andInfo = new DataLine.Info(Clip.class, andFormat);
     
    try {
     
    	theTimeIsClip = (Clip) AudioSystem.getLine(theTimeIsInfo);
    	timeForClip = (Clip) AudioSystem.getLine(timeForInfo);
    	repeatClip = (Clip) AudioSystem.getLine(repeatInfo);
    	dexClip = (Clip) AudioSystem.getLine(dexInfo);
    	hydClip = (Clip) AudioSystem.getLine(hydInfo);
    	gabClip = (Clip) AudioSystem.getLine(gabInfo);
    	andClip = (Clip) AudioSystem.getLine(andInfo);
    } 
    	catch(LineUnavailableException ex) {
    		System.out.println("Audio line unavailable exception in FilePlayer static initialization block.");
    		System.exit(1);
     
    }
     
    try {
     
    	theTimeIsClip.open(theTimeIsStream);
    	timeForClip.open(timeForStream);
    	repeatClip.open(repeatStream);
    	dexClip.open(dexStream);
    	hydClip.open(hydStream);
    	gabClip.open(gabStream);
    	andClip.open(andStream);
    } 
    	catch(LineUnavailableException ex) {
    		System.out.println("LU-Ex in FilePlayer static-init-block opening methods.");
    		System.exit(1);
    }
    	catch(IOException ex) {
    		System.out.println("IOEx in FilePlayer static-init-block opening methods.");
    		System.exit(1);
    }
    }
     
    private static double theTimeIsTimeVar, timeForTimeVar, repeatTimeVar, dexTimeVar, hydTimeVar, gabTimeVar, andTimeVar;
    private static long theTimeIsTime, timeForTime, repeatTime, dexTime, hydTime, gabTime, andTime;
     
    static {
     
    theTimeIsTimeVar = theTimeIsClip.getMicrosecondLength() * 0.001;
    timeForTimeVar =  timeForClip.getMicrosecondLength() * 0.001;
    repeatTimeVar =   repeatClip.getMicrosecondLength() * 0.001;
    dexTimeVar =  dexClip.getMicrosecondLength() * 0.001;
    hydTimeVar =  hydClip.getMicrosecondLength() * 0.001;
    gabTimeVar = gabClip.getMicrosecondLength() * 0.001;
    andTimeVar = andClip.getMicrosecondLength() * 0.001;
     
    BigDecimal theTimeIsBD = new BigDecimal(theTimeIsTimeVar);
    BigDecimal timeForBD = new BigDecimal(timeForTimeVar);
    BigDecimal repeatBD = new BigDecimal(repeatTimeVar);
    BigDecimal dexBD = new BigDecimal(dexTimeVar);
    BigDecimal hydBD = new BigDecimal(hydTimeVar);
    BigDecimal gabBD = new BigDecimal(gabTimeVar);
    BigDecimal andBD = new BigDecimal(andTimeVar);
     
    theTimeIsTime = theTimeIsBD.longValue();
    timeForTime = timeForBD.longValue();
    repeatTime = repeatBD.longValue();
    dexTime = dexBD.longValue();
    hydTime = hydBD.longValue();
    gabTime = gabBD.longValue();
    andTime = andBD.longValue();
    }
     
    public FilePlayer(int time) {
     
    	this.time = time;
     
    	}
     
    public void playAudio() {
     
     
    	switch(time) {
     
    		case 7: try {play07();}
    		             catch(IOException ex) {System.out.println("IOEx in FP switchblock (method play07())."); System.exit(1);}
    		             catch(UnsupportedAudioFileException ex) {System.out.println("USAF-Ex in FP switch method 07."); System.exit(1);}
    		             catch(LineUnavailableException ex) {System.out.println("LU-Ex FP SB m-7."); System.exit(1);}
    		             catch(InterruptedException ex) {System.out.println("INT-Ex FP SB m-7."); System.exit(1);}
    		             break;
    		case 11: try {play11();}
    		             catch(IOException ex) {System.out.println("IOEx in FP switchblock (method play11())."); System.exit(1);}
    		             catch(UnsupportedAudioFileException ex) {System.out.println("USAF-Ex in FP switch method 11."); System.exit(1);}
    		             catch(LineUnavailableException ex) {System.out.println("LU-Ex FP SB m-11."); System.exit(1);}
    		             catch(InterruptedException ex) {System.out.println("INT-Ex FP SB m-11."); System.exit(1);}
    		             break;
    		case 15: try {play15();}
    		              catch(IOException ex) {System.out.println("IOEx in FP switchblock (method play15())."); System.exit(1);}
    		              catch(UnsupportedAudioFileException ex) {System.out.println("USAF-Ex in FP switch method 15."); System.exit(1);}
    		              catch(LineUnavailableException ex) {System.out.println("LU-Ex FP SB m-15."); System.exit(1);}
    		              catch(InterruptedException ex) {System.out.println("INT-Ex FP SB m-15."); System.exit(1);}
    		              break;
    		case 19: try {play19();}
    		             catch(IOException ex) {System.out.println("IOEx in FP switchblock (method play19())."); System.exit(1);}
    		             catch(UnsupportedAudioFileException ex) {System.out.println("USAF-Ex in FP switch method 19."); System.exit(1);}
    		             catch(LineUnavailableException ex) {System.out.println("LU-Ex FP SB m-19."); System.exit(1);}
    		             catch(InterruptedException ex) {System.out.println("INT-Ex FP SB m-19."); System.exit(1);}
    		             break;
    		}
     
    	}
     
    private void play07() throws UnsupportedAudioFileException, LineUnavailableException, InterruptedException, IOException {
     
     
    		for(int i = 0; i < 2; i++) {
     
     
    		theTimeIsClip.start();
    		Thread.currentThread().sleep(theTimeIsTime);
    		theTimeIsClip.stop();
    		theTimeIsClip.setFramePosition(0);
     
    		Clip timeClip;
    		File timeFile = new File("C:/PillMonitor/ProgramData/Audio/07.wav");
    		AudioInputStream stream = AudioSystem.getAudioInputStream(timeFile);
    		AudioFormat format = stream.getFormat();
    		DataLine.Info infos = new DataLine.Info(Clip.class, format);
    		timeClip = (Clip) AudioSystem.getLine(infos);
    		timeClip.open(stream);
    		double timeTimeVar = timeClip.getMicrosecondLength() * 0.001;
    		BigDecimal timeTimeBD = new BigDecimal(timeTimeVar);	
    		long timeTime = timeTimeBD.longValue();
    		timeClip.start();
    		Thread.currentThread().sleep(timeTime);
    		timeClip.stop();
    		timeClip.setFramePosition(0);
     
    		timeForClip.start();
    		Thread.currentThread().sleep(timeForTime);
    		timeForClip.stop();
    		timeForClip.setFramePosition(0);
     
    		dexClip.start();
    		Thread.currentThread().sleep(dexTime);
    		dexClip.stop();
    		dexClip.setFramePosition(0);
     
    		andClip.start();
    		Thread.currentThread().sleep(dexTime);
    		andClip.stop();
    		andClip.setFramePosition(0);
     
    		hydClip.start();
    		Thread.currentThread().sleep(dexTime);
    		hydClip.stop();
    		hydClip.setFramePosition(0);
     
    		if(i != 0) {
    		break;
    		}
     
    		repeatClip.start();
    		Thread.currentThread().sleep(repeatTime);
    		repeatClip.stop();
    		repeatClip.setFramePosition(0);
    		}
    	}
     
    private void play11() throws UnsupportedAudioFileException, LineUnavailableException, InterruptedException, IOException {
     
    	for(int i = 0; i < 2; i++) {
     
    		theTimeIsClip.start();
     
    		Thread.currentThread().sleep(theTimeIsTime);
    		theTimeIsClip.stop();
    		theTimeIsClip.setFramePosition(0);
     
    		Clip timeClip;
    		File timeFile = new File("C:/PillMonitor/ProgramData/Audio/11.wav");
    		AudioInputStream stream = AudioSystem.getAudioInputStream(timeFile);
    		AudioFormat format = stream.getFormat();
    		DataLine.Info infos = new DataLine.Info(Clip.class, format);
    		timeClip = (Clip) AudioSystem.getLine(infos);
    		timeClip.open(stream);
    		double timeTimeVar = timeClip.getMicrosecondLength() * 0.001;
    		BigDecimal timeTimeBD = new BigDecimal(timeTimeVar);	
    		long timeTime = timeTimeBD.longValue();
    		timeClip.start();
    		Thread.currentThread().sleep(timeTime);
    		timeClip.stop();
    		timeClip.setFramePosition(0);
     
    		timeForClip.start();
    		Thread.currentThread().sleep(timeForTime);
    		timeForClip.stop();
    		timeForClip.setFramePosition(0);
     
    		hydClip.start();
    		Thread.currentThread().sleep(hydTime);
    		hydClip.stop();
    		hydClip.setFramePosition(0);
     
     
    		if(i != 0)
    		break;
     
    		repeatClip.start();
    		Thread.currentThread().sleep(repeatTime);
    		repeatClip.stop();
    		repeatClip.setFramePosition(0);
    		}
    	}
     
    private void play15() throws UnsupportedAudioFileException, LineUnavailableException, InterruptedException, IOException {
     
    	for(int i = 0; i < 2; i++) {
     
    		theTimeIsClip.start();
    		Thread.currentThread().sleep(theTimeIsTime);
    		theTimeIsClip.stop();
    		theTimeIsClip.setFramePosition(0);
     
    		Clip timeClip;
    		File timeFile = new File("C:/PillMonitor/ProgramData/Audio/15.wav");
    		AudioInputStream stream = AudioSystem.getAudioInputStream(timeFile);
    		AudioFormat format = stream.getFormat();
    		DataLine.Info infos = new DataLine.Info(Clip.class, format);
    		timeClip = (Clip) AudioSystem.getLine(infos);
    		timeClip.open(stream);
    		double timeTimeVar = timeClip.getMicrosecondLength() * 0.001;
    		BigDecimal timeTimeBD = new BigDecimal(timeTimeVar);	
    		long timeTime = timeTimeBD.longValue();
    		timeClip.start();
    		Thread.currentThread().sleep(timeTime);
    		timeClip.stop();
    		timeClip.setFramePosition(0);
     
    		timeForClip.start();
    		Thread.currentThread().sleep(timeForTime);
    		timeForClip.stop();
    		timeForClip.setFramePosition(0);
     
    		hydClip.start();
    		Thread.currentThread().sleep(hydTime);
    		hydClip.stop();
    		hydClip.setFramePosition(0);
     
    		if(i != 0)
    		break;
     
    		repeatClip.start();
    		Thread.currentThread().sleep(repeatTime);
    		repeatClip.stop();
    		repeatClip.setFramePosition(0);
    	}
    }
     
    private void play19() throws UnsupportedAudioFileException, LineUnavailableException, InterruptedException, IOException {
     
    	for(int i = 0; i < 2; i++) {
     
    		theTimeIsClip.start();
    		Thread.currentThread().sleep(theTimeIsTime);
    		theTimeIsClip.stop();
    		theTimeIsClip.setFramePosition(0);
     
    		Clip timeClip;
    		File timeFile = new File("C:/PillMonitor/ProgramData/Audio/19.wav");
    		AudioInputStream stream = AudioSystem.getAudioInputStream(timeFile);
    		AudioFormat format = stream.getFormat();
    		DataLine.Info infos = new DataLine.Info(Clip.class, format);
    		timeClip = (Clip) AudioSystem.getLine(infos);
    		timeClip.open(stream);
    		double timeTimeVar = timeClip.getMicrosecondLength() * 0.001;
    		BigDecimal timeTimeBD = new BigDecimal(timeTimeVar);	
    		long timeTime = timeTimeBD.longValue();
    		timeClip.start();
    		Thread.currentThread().sleep(timeTime);
    		timeClip.stop();
    		timeClip.setFramePosition(0);
     
    		timeForClip.start();
    		Thread.currentThread().sleep(timeForTime);
    		timeForClip.stop();
    		timeForClip.setFramePosition(0);
     
    		hydClip.start();
    		Thread.currentThread().sleep(hydTime);
    		hydClip.stop();
    		hydClip.setFramePosition(0);
     
    		andClip.start();
    		Thread.currentThread().sleep(andTime);
    		andClip.stop();
    		andClip.setFramePosition(0);
     
    		gabClip.start();
    		Thread.currentThread().sleep(gabTime);
    		gabClip.stop();
    		gabClip.setFramePosition(0);
     
    		if(i != 0)
    		break;
     
    		repeatClip.start();
    		Thread.currentThread().sleep(repeatTime);
    		repeatClip.stop();
    		repeatClip.setFramePosition(0);
    	}
    }
    }
     
    class WaitingMachine {
     
    public static int waitFor() {
     
    		while(Calendar.getInstance().get(Calendar.HOUR_OF_DAY) != 7 && Calendar.getInstance().get(Calendar.HOUR_OF_DAY) != 11 && Calendar.getInstance().get(Calendar.HOUR_OF_DAY) != 15 && Calendar.getInstance().get(Calendar.HOUR_OF_DAY) != 19 || Calendar.getInstance().get(Calendar.SECOND) != 0 || Calendar.getInstance().get(Calendar.MINUTE) != 0) {
    			continue;
    		}
     
    	Calendar calendar = Calendar.getInstance();
    	return calendar.get(Calendar.HOUR_OF_DAY);
     
    	}
     
     
     
    }
     
    public class PillMonitor {
     
    public static void main(String[] args) {
     
    	System.out.println("Pill Monitor v1.1.  Do not close this window.");
     
    		for(;;) {
    		int pillTimer = WaitingMachine.waitFor();
    		new Watcher(pillTimer).start();
    		FilePlayer player = new FilePlayer(pillTimer);
    		player.playAudio();
    		}
     
    	}
     
    }
     
    class Watcher extends Thread{
     
    private int hour;
    private static boolean isWritten = false;
    private static Scanner scanner = new Scanner(System.in);
     
     
    public Watcher(int hour) {
     
    	this.hour = hour;
    }
     
     
    @Override
    public void run() {
     
    	int localHour = hour;
    	if(hour == 15)
    		localHour = 3;
    	else if(hour == 19)
    		localHour = 7;
     
    	if(isWritten) {
    			System.out.println("\n\t-ALERT:  Pill not taken or registered.");
    			}
     
    	System.out.printf("\nLast pill: %s          Time: %d", getPill(hour), localHour);
    	System.out.print(":00");
    	if(hour == 7 || hour == 11 )
    		System.out.print(" AM");
    	else
    		System.out.print(" PM");
     
     
    	if(!isWritten) {
    		isWritten = true;
    		long skip = 0;
    		try { 
    			skip = System.in.available();
    		} catch(IOException ex) {
    			System.out.println("\nIOException in Watcher thread, System.in.available() method.");
    			System.exit(1);
    		}
    		if(skip != 0) {
    			try {
    				System.in.skip(skip);
    			} catch(IOException ex) {
    				System.out.println("\nIOException in Watcher thread, System.in.skip() method.");
    				System.exit(1);
    			}
    		}
    		scanner.nextLine();
     
    	System.out.print("\t-Pill taken\n");
    	isWritten = false;
     
    	}
    }
     
    private static String getPill(int h) {
    	String s = "";
    	switch(h) {
    		case 7: s = "Dexa and Hydro";
    		break;
     
     
    		case 11:
    		case 15:
    			s = "Hydro";
    		break;			
    		case 19: s = "Hydro and Gaba";
    		break;
     
    		}
    	return s;
    	}
    }

    -summit45

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Automatic audio file player not working

    To get the time to sleep, get the current time and subtract it from the desired alarm time. Do all the calculations using the time as UTC milliseconds from the epoch. The Calendar class has a method that returns that value and the System class's currentTimeMillis() method does also.

    Have you looked at CPU usage when your code is executing? Is it possible to do any other work on your PC when the program is running?
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Member
    Join Date
    Jul 2013
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Automatic audio file player not working

    Well, this forum just lost me my last two posts, so here goes an approximate re-do:

    You were right about the CPU usage! I had no idea it would be that bad over a little loop. But yeah, I have re-done it - thank you very much for pointing that out to me.

    Here is what I have now (of the WaitingMachine class). Seems to be working:

    class WaitingMachine {
     
    private long target8, target12, target16, target20;
    private long midnight;
     
    {
     
    Date target8Date, target12Date, target16Date, target20Date;
     
    Calendar target8Cal = Calendar.getInstance();
    Calendar target12Cal = Calendar.getInstance();
    Calendar target16Cal = Calendar.getInstance();
    Calendar target20Cal = Calendar.getInstance();
     
    Calendar[] calAr = new Calendar[4];
    calAr[0] = target8Cal;
    calAr[1] = target12Cal;
    calAr[2] = target16Cal;
    calAr[3] = target20Cal;
     
    	for(int i = 0; i < calAr.length; i++) {
    		calAr[i].set(calAr[i].MINUTE, 0);
    		calAr[i].set(calAr[i].SECOND, 0);
    		calAr[i].set(calAr[i].MILLISECOND, 0);
    		}
    calAr[0].set(calAr[0].HOUR_OF_DAY, 8);
    calAr[1].set(calAr[1].HOUR_OF_DAY, 12);
    calAr[2].set(calAr[2].HOUR_OF_DAY, 16);
    calAr[3].set(calAr[3].HOUR_OF_DAY, 20);
     
    	target8Date = calAr[0].getTime();
    	target12Date = calAr[1].getTime();
    	target16Date = calAr[2].getTime();
    	target20Date = calAr[3].getTime();
     
    	target8 = target8Date.getTime();
    	target12 = target12Date.getTime();
    	target16 = target16Date.getTime();
    	target20 = target20Date.getTime();
     
    Calendar midNight = Calendar.getInstance();
    midNight.set(midNight.HOUR_OF_DAY, 0);
    midNight.set(midNight.MINUTE, 0);
    midNight.set(midNight.SECOND, 0);
    midNight.set(midNight.MILLISECOND, 0);
     
    Date nightDate = midNight.getTime();
    midnight = nightDate.getTime();
    }
     
    private long currentTime;
    private long currentTarget;
    private boolean nightFlag = false;
     
    public WaitingMachine() {
     
    currentTime = System.currentTimeMillis();
     
    	if(midnight <= currentTime && currentTime <= target8)
    		currentTarget = target8;
    	else if(target8 < currentTime && currentTime <= target12)
    		currentTarget = target12;
    	else if(target12 < currentTime && currentTime <= target16)
    		currentTarget = target16;
    	else if(target16 < currentTime && currentTime <= target20)
    		currentTarget = target20;
    	else
    		nightFlag = true;
    }
     
    public int waitFor() {
    	if(nightFlag) 
    		nightWatch();
     
    try {
    	Thread.currentThread().sleep((currentTarget - currentTime) + 100);
    	} catch(InterruptedException ex) {
    		System.out.println("Interrupt exception in waitFor() sleep() method.");
    		System.exit(1);
    		}
    return Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
     
    	}
     
    private void nightWatch() {
     
    	try {
    		Thread.currentThread().sleep((midnight - currentTime) + 100);
    		} catch(InterruptedException ex) {
    			System.out.println("Interrupt exception in nightWatch() sleep() method.");
    			System.exit(1);
    			}
    	nightFlag = false;
    	currentTime = System.currentTimeMillis();
    	currentTarget = target8;
     
    	}
    }

    -summit45

    --- Update ---

    Well it's working except nightWatch(). I have to make it so midnight references TOMORROW'S midnight, because now it's referencing the midnight of the current day.

    -summit45

    --- Update ---

    I got it, here it is:

    class WaitingMachine {
     
    private  long target8, target12, target16, target20;
    private long midnight;
     
    {
     
    Date target8Date, target12Date, target16Date, target20Date;
     
    Calendar target8Cal = Calendar.getInstance();
    Calendar target12Cal = Calendar.getInstance();
    Calendar target16Cal = Calendar.getInstance();
    Calendar target20Cal = Calendar.getInstance();
     
    Calendar[] calAr = new Calendar[4];
    calAr[0] = target8Cal;
    calAr[1] = target12Cal;
    calAr[2] = target16Cal;
    calAr[3] = target20Cal;
     
    	for(int i = 0; i < calAr.length; i++) {
    		calAr[i].set(calAr[i].MINUTE, 0);
    		calAr[i].set(calAr[i].SECOND, 0);
    		calAr[i].set(calAr[i].MILLISECOND, 0);
    		}
    calAr[0].set(calAr[0].HOUR_OF_DAY, 8);
    calAr[1].set(calAr[1].HOUR_OF_DAY, 12);
    calAr[2].set(calAr[2].HOUR_OF_DAY, 16);
    calAr[3].set(calAr[3].HOUR_OF_DAY, 20);
     
    	target8Date = calAr[0].getTime();
    	target12Date = calAr[1].getTime();
    	target16Date = calAr[2].getTime();
    	target20Date = calAr[3].getTime();
     
    	target8 = target8Date.getTime();
    	target12 = target12Date.getTime();
    	target16 = target16Date.getTime();
    	target20 = target20Date.getTime();
     
    Calendar midNight = Calendar.getInstance();
    midNight.set(midNight.DAY_OF_MONTH, (Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + 1));
    midNight.set(midNight.HOUR_OF_DAY, 0);
    midNight.set(midNight.MINUTE, 0);
    midNight.set(midNight.SECOND, 0);
    midNight.set(midNight.MILLISECOND, 0);
     
    Date nightDate = midNight.getTime();
    midnight = nightDate.getTime();
    }
     
    private long currentTime;
    private long currentTarget;
    private boolean nightFlag = false;
     
    public WaitingMachine() {
     
    currentTime = System.currentTimeMillis();
     
    	if(midnight <= currentTime && currentTime <= target8)
    		currentTarget = target8;
    	else if(target8 < currentTime && currentTime <= target12)
    		currentTarget = target12;
    	else if(target12 < currentTime && currentTime <= target16)
    		currentTarget = target16;
    	else if(target16 < currentTime && currentTime <= target20)
    		currentTarget = target20;
    	else
    		nightFlag = true;
    }
     
    public int waitFor() {
    	if(nightFlag) 
    		nightWatch();
     
    try {
    	Thread.currentThread().sleep((currentTarget - currentTime) + 100);
    	} catch(InterruptedException ex) {
    		System.out.println("Interrupt exception in waitFor() sleep() method.");
    		System.exit(1);
    		}
    return Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
     
    	}
     
    private void nightWatch() {
     
    	try {
    		Thread.currentThread().sleep((midnight - currentTime) + 100);
    		} catch(InterruptedException ex) {
    			System.out.println("Interrupt exception in nightWatch() sleep() method.");
    			System.exit(1);
    			}
    	nightFlag = false;
    	currentTime = System.currentTimeMillis();
    	currentTarget = target8;
     
    	}
    }

    -summit45

    --- Update ---

    Altered so that the next morning's 8 AM will be the actual next morning and not yesterday's 8 (I apologize for the millions of double-posts but that's the forum's error, not mine):

    class WaitingMachine {
     
    private long target8, target12, target16, target20;
    private long midnight, nextMorning;
     
    {
     
    Date target8Date, target12Date, target16Date, target20Date;
     
    Calendar target8Cal = Calendar.getInstance();
    Calendar target12Cal = Calendar.getInstance();
    Calendar target16Cal = Calendar.getInstance();
    Calendar target20Cal = Calendar.getInstance();
     
    Calendar[] calAr = new Calendar[4];
    calAr[0] = target8Cal;
    calAr[1] = target12Cal;
    calAr[2] = target16Cal;
    calAr[3] = target20Cal;
     
    	for(int i = 0; i < calAr.length; i++) {
    		calAr[i].set(calAr[i].MINUTE, 0);
    		calAr[i].set(calAr[i].SECOND, 0);
    		calAr[i].set(calAr[i].MILLISECOND, 0);
    		}
    calAr[0].set(calAr[0].HOUR_OF_DAY, 8);
    calAr[1].set(calAr[1].HOUR_OF_DAY, 12);
    calAr[2].set(calAr[2].HOUR_OF_DAY, 16);
    calAr[3].set(calAr[3].HOUR_OF_DAY, 20);
     
    Calendar morning = calAr[0];
    morning.set(morning.DAY_OF_MONTH, (morning.get(morning.DAY_OF_MONTH) + 1));
    Date mornDate = morning.getTime();
    nextMorning = mornDate.getTime();
     
    	target8Date = calAr[0].getTime();
    	target12Date = calAr[1].getTime();
    	target16Date = calAr[2].getTime();
    	target20Date = calAr[3].getTime();
     
    	target8 = target8Date.getTime();
    	target12 = target12Date.getTime();
    	target16 = target16Date.getTime();
    	target20 = target20Date.getTime();
     
    Calendar midNight = Calendar.getInstance();
    midNight.set(midNight.DAY_OF_MONTH, (Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + 1));
    midNight.set(midNight.HOUR_OF_DAY, 0);
    midNight.set(midNight.MINUTE, 0);
    midNight.set(midNight.SECOND, 0);
    midNight.set(midNight.MILLISECOND, 0);
     
    Date nightDate = midNight.getTime();
    midnight = nightDate.getTime();
    }
     
    private long currentTime;
    private long currentTarget;
    private boolean nightFlag = false;
     
    public WaitingMachine() {
     
    currentTime = System.currentTimeMillis();
     
    	if(midnight <= currentTime && currentTime <= target8)
    		currentTarget = target8;
    	else if(target8 < currentTime && currentTime <= target12)
    		currentTarget = target12;
    	else if(target12 < currentTime && currentTime <= target16)
    		currentTarget = target16;
    	else if(target16 < currentTime && currentTime <= target20)
    		currentTarget = target20;
    	else
    		nightFlag = true;
    }
     
    public int waitFor() {
    	if(nightFlag) 
    		nightWatch();
     
    try {
    	Thread.currentThread().sleep((currentTarget - currentTime) + 100);
    	} catch(InterruptedException ex) {
    		System.out.println("Interrupt exception in waitFor() sleep() method.");
    		System.exit(1);
    		}
    return Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
     
    	}
     
    private void nightWatch() {
     
    	try {
    		Thread.currentThread().sleep((midnight - currentTime) + 100);
    		} catch(InterruptedException ex) {
    			System.out.println("Interrupt exception in nightWatch() sleep() method.");
    			System.exit(1);
    			}
    	nightFlag = false;
    	currentTime = System.currentTimeMillis();
    	currentTarget = nextMorning;
     
    	}
    }

    -summit45

    --- Update ---

    Code fixed so it won't throw an exception at the end of the month. Not reposting the code again because I'm beginning to feel like a creep spamming this thread.

    -summit45

  20. #20
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Automatic audio file player not working

    Quote Originally Posted by summit45 View Post
    (I apologize for the millions of double-posts but that's the forum's error, not mine):
    I'm beginning to feel like a creep spamming this thread.
    All of those posts will become one post with updates. Just ignore it

  21. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Automatic audio file player not working

    Does the code work? There are no comments in the code so I have no idea what it is trying to do.
    If you don't understand my answer, don't ignore it, ask a question.

  22. #22
    Member
    Join Date
    Jul 2013
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Automatic audio file player not working

    Quote Originally Posted by Norm View Post
    Does the code work? There are no comments in the code so I have no idea what it is trying to do.
    It just does what you said. Declares Calendar objects representing each target time, and parses their Epoch time through a Date object into a long var. Then establishes the current Epoch time, and sleeps at a value of targetTime - currentTime + 100 (the 100 is so that it returns the right hour and not the hour before).

    It has functions to let it sleep the night (it sleeps til midnight, then sleeps again from midnight to 8 AM), and also I changed the code to go off DAY_OF_YEAR instead of DAY_OF_MONTH otherwise it would have thrown an exception at the end of each month where midnight and nextMorning are set to an incrementation of the day.

    -summit45

  23. #23
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Automatic audio file player not working

    The comments about what the code does should be in the code. Posting documentation about here doesn't help someone when they are reading the code and trying to figure out what it is supposed to do and why it is coded the way it is.
    If you don't understand my answer, don't ignore it, ask a question.

  24. #24
    Member
    Join Date
    Jul 2013
    Posts
    47
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Automatic audio file player not working

    Quote Originally Posted by Norm View Post
    The comments about what the code does should be in the code. Posting documentation about here doesn't help someone when they are reading the code and trying to figure out what it is supposed to do and why it is coded the way it is.
    Believe me when I tell you that I'm pretty confident no human being besides me is ever going to have to reprogram this, and if that day comes, I will put comments in it.

    -summit45

  25. #25
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Automatic audio file player not working

    Then there is no need to post the code on the forum if you don't want someone to read the code and try to understand it.
    If you don't understand my answer, don't ignore it, ask a question.

Page 1 of 2 12 LastLast

Similar Threads

  1. audio not working HELP
    By silverpen10 in forum The Cafe
    Replies: 0
    Last Post: December 19th, 2012, 02:29 PM
  2. [SOLVED] Collsion Not Working Between Player And Enmey ...Java
    By hwoarang69 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 28th, 2012, 06:47 AM
  3. How do I upload an audio wav file?!
    By mcgras22 in forum File Input/Output Tutorials
    Replies: 5
    Last Post: June 15th, 2012, 08:29 PM
  4. Reading Audio file
    By madhura.yerawar in forum Java Theory & Questions
    Replies: 0
    Last Post: January 21st, 2012, 01:05 AM
  5. How to play Audio file?
    By sush in forum Object Oriented Programming
    Replies: 3
    Last Post: June 29th, 2011, 08:11 AM