Win a copy of Penetration Testing Basics this week in the Security forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Sound API problems

Gary Richards
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I've been using the Java Sound API's to play some audio tracks (Ogg Vorbis and mp3). I've been using the VorbisSPI and MP3SPI from to support these file formats. I have code sucessfully playing these formats, starting, stopping, pausing resuming. However when I first create my 'Line', it takes around 2-3 seconds for each audio track to play. The code is something like this:

I then have code in a seperate thread which reads in the bytes of audio data and writes them out to the currentLnie, something like this:

As I have said, by doing this, it takes 2-3 seconds between calling this method and my audio to start playing. I originally thought it to be a problem with my creation of the Thread. So when my object is created it now creates the Thread and starts it. This then sits in a while loop sleeping for 100ms at a time whilst not playing. Yet it still takes 203 seconds before the audio starts to play. If I do the following:

To essentially 'pause' the audio, and then sometime later I do:

Which essentially 'resumes' my audio playing again, it resumes instantly.
Therefore the only thing I can put this down to is the time it's taking to create all of the objects to eventually end up with the currentLine object that I use to play that audio.

So... can anyone suggest a way that I can either rewrite this to speed it up, so it plays the audio instantly. Or is there a way I can create a Line or maybe two Line's that I can keep open and use ti play audio instantly each time (if that actually makes sense)?

Ahy help with this is greatly appreciated.

  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic