• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
  • Tim Holloway
  • Carey Brown
  • salvin francis

Java Sound API problems

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 Javazoon.net 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.

I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!