• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is there a way to loop until AudioPlayer has stopped?  RSS feed

 
Paul Carter
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • 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());
}
}
 
Petrus Pelser
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!