Loop a sound file from a certain point?

Suppose I have a sound file that I wish to play in this manner:

  1. Start from the 0:00 mark.
  2. When the sound file ends, replay from the 0:30.00 mark.

Essentially, I wish for the song to play from 0:00 to 0:30, then loop from 0:30 to the end.

How do you do this?

Usually, when playing Audio Files, I use AudioClip.

AudioClip audio = Applet.newAudioClip( this.getClass().getResource( "..." ) );
audio.loop();

It's because of bad experiences with loading the audio file when the project is packed into a .jar file. If the method you recommend uses another class, I would still be more than happy to listen. However, if you've encountered the same problem as I have and know how to fix it, please do tell me.

Upvotes: 0

Views: 170

Answers (1)

Andrew Thompson
Andrew Thompson

Reputation: 168825

You might use a Clip for this, or if the clip is too large, feed the bytes directly to a SourceDataLine.

Upvotes: 1

Related Questions