> 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?

Why do call AudioPlayer.stop() ?

AudioPlayer.start() - implicitly spawns a thread to send the audio data to
the audio device via a stream buffer.

Calling AudioPlayer.stop() - terminates the thread, n'est pas ?

Unless your program exits soon after AudioPlayer.start() you
do not need to sleep for X milliseconds.




Cheers

Peter

--
Peter Pilgrim  Deutsche Bank (UK) Ltd

"I'd be an eagle because I love its way of flying and if I were an
angel I'd simply be Eric Cantona with big wings. If I were a sport I'd
be football, of course, and if I were a film I'd be Raging Bull. If I
were any child I would be my children but if I were Eric Cantona I'd
be proud."
        On himself

        Vive Manchester United Football Club

Reply via email to