Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Java Sound API problems

Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic