Programmer
Programmer

Reputation: 6753

Loading audio files and playing them at specific positions in java

I have a collection of audio files in my folder. Now, I want to load all these audio files into the memory using Java to save read time later on. Moreover, the user has the option to choose which audio file he wants to play and at what position.

Can someone suggest me suitable API to

  1. Load all the audio files in memory
  2. Play the audio file at the correct position.

I have heard of the Clip library but I heard it only stores audio worth 1 second. Any suggestions ?

If it helps, the audio files in my case are 4 minutes long each and I have 40 of them.

Upvotes: 1

Views: 1100

Answers (3)

Andrew Thompson
Andrew Thompson

Reputation: 168845

For a Clip that can use the available (to the app.) RAM see BigClip.

..the BigClip class through a outof memory exception.

It would in a JRE with standard memory. I have a DukeBox for my music collection. It plays typical MP3s (stereo, 16 bit, 44.1KHz) of up to 20 minutes length within 512 Meg of memory assigned to the app.

You still have not specified what format the sound is, so it is impossible to say how much memory the 160 minutes of audio would require, beyond 'a lot'.

OTOH, you might find the time required to load each BigClip individually, is not very long. My software is designed to load directly off local disk and is wrapped in a default ProgressMonitorInputStream. The progress dialog only appear rarely - and only for tracks that play in excess of 12-14 minutes. Doing it 'one at a time' might work within the standard memory, for your sound samples.


..4 minutes long each and I have 40..

The size in memory required to contain that 160 minutes of audio would differ by a factor of (BOTE) 16 - between a high (44100 KHz)/low (11025 KHz) sampling rate, mono/stereo and 8/16 bit representation audio format.

Lower resolution

160 min * 
60 SecPerMin * 
11025 KHz * 
1 mono * 
1 byte (8 bit) 
= 
105,840,000 bytes 

Or approximately 105 meg for the lower limit.

Upvotes: 1

d1e
d1e

Reputation: 6452

There is a Java API for this, called Java Media Framework (JMF). Official page says:

The Java Media Framework API (JMF) enables audio, video and other time-based media to be added to applications and applets built on Java technology. This optional package, which can capture, playback, stream, and transcode multiple media formats, extends the Java 2 Platform, Standard Edition (J2SE) for multimedia developers by providing a powerful toolkit to develop scalable, cross-platform technology.

Here are additional resources:

  1. Official overview

  2. Article: Process multimedia with the Java Media Framework API By Peter Mikhalenko

Upvotes: 0

Related Questions