• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is there a way to loop until AudioPlayer has stopped?

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using the following code to play wavs.

Is there any way I can get it to loop until it has stopped playing?

Thanks in advance

Paul.

public static void PlayAudio(int audioNo)
{

if ( audioNo > NA )
try {
InputStream in = new FileInputStream("C:/DTaudio/" + AUDIO[audioNo] + ".wav");
AudioStream as = new AudioStream(in);
AudioPlayer.player.start(as);
} catch (FileNotFoundException e) {
System.err.println("FileNotFoundException: " + e.getMessage());
} catch (IOException e) {
System.err.println("Caught IOException: " + e.getMessage());
}
}
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try something like:



in your player.start() method where you read from the file.
 
Paul Carter
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What type of variable should 'something' be? (getting error cannot find symbol);

Regards

Paul.
 
Petrus Pelser
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That would be the variable to hold the data you read from the file.
 
Paul Carter
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Petrus I'm an idiot.

How would it work in the following example?

I've tried
while (inStream = aStream.read() != null) {};
but as as.read() seems to return an integer they do not seem compatible.

InputStream inStream = new FileInputStream("C:/DTaudio/" + AUDIO[audioNo] + ".wav");
AudioStream aStream = new AudioStream(inStream);
AudioPlayer.player.start(aStream);
 
Petrus Pelser
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you post the part of the AudioPlayer.player.start(aStream) method that reads from the stream.
 
Paul Carter
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Petrus

AudioStream is apparently an undocumented function in sun.audio.*

The code in my first post is my current sound code in its entirity.
 
Petrus Pelser
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I assumed it would function like a normal stream. Maybe if you could find the source for the player class it would help in understanding how the start() method reads from the stream.
 
Petrus Pelser
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at How to play audio in applications

I'm sure some googling should help you find some tutorials.
[ November 01, 2006: Message edited by: Petrus Pelser ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic