Hello,

I'am trying to play a simple audio(.au) file from an application. When I run my
application I only hear the beginning of the audio file. Here is the program.

import sun.audio.*;
import java.io.*;

public class Sound {
                
  public void play(String soundfile)    {
        File theFile = null;
        AudioData theData = null;
        AudioStream as = null;
        try {
          theFile = new File(soundfile);
          if (theFile != null) {
            InputStream fis = new FileInputStream(theFile);
            as = new AudioStream(fis);
            theData = as.getData();
          }
        }
        catch (IOException e) {
          System.err.println(e);
        }
        AudioDataStream ads = new AudioDataStream(theData);
        AudioPlayer.player.start(ads);
//    try{ Thread.sleep(1500); }
//    catch(Exception e){ System.out.println("sleep failed"); }
//     AudioPlayer.player.stop(as);     
  }

  public static void main(String[] args) {
    Sound snd=new Sound();              
    snd.play("sound.au");  
  }
}

When I unmark the sleep, I hear the whole audio file. But that is offcourse not
the correct solution.

I tested the application on different platforms and using severel jdk's with 
the same results. Playing the audio file with an audio tool works fine.

Somebody a clue?

Thanks for reading so far.

Erik.

Reply via email to