0

Is there a way, using Java, that I can have an audio file(of any format, whichever can work for this), that is played, starting from the beginning, up until x samples have been played, then continues playing until y samples have been played, then loops the audio back to x samples?

Or if samples could be expressed as time/seconds that would also work. Is there a way to do this? I'm hoping to use this to play an intro to a background song, then loop it excluding the intro.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
user2649681
  • 750
  • 1
  • 6
  • 23

1 Answers1

0

You can convert from samples to time fairly easy. If you want to achieve this though, you need to know the sampling rate of your audio. Most audio files will have a sampling rate of 44100 Hz (CD industry standard for sampling rates.) This means that for one second of audio, you will have 44100 samples. So two seconds of audio will 44100*2, and half a second of audio will be 44100*0.5.

You can also loop audio with the audio library called minim. It's designed for processing, but it can be incorporated into java pretty easily I've heard.

http://code.compartmental.net/tools/minim/

Hope that helps.

PicnicTripper
  • 295
  • 1
  • 3
  • I wasn't asking how to convert between samples and time, but I'll check out the library and see if it has what I'm looking for. – user2649681 May 06 '15 at 14:59