开发者

How should I cache an audio file in Java (using JLayer)?

I'm developing an application that necessitates the use of sound files (through the JLayer audio library at the moment) and am wondering if it is possible to cache a file in memory so that it doesn't have to be read off of the hard disk every time it's needed.

For example, I can store an image in a Buffere开发者_如何学PythondImage object instead of calling ImageIO.read every time I need an image; is there a similar way to approach this using JLayer? Should I use a different audio library? I just don't want to be hitting the disk every time the user triggers a sound (potentially many times per second).

If it makes a difference, the audio is in MP3 format.


You can read any file (up to a certain size) into a byte[] and process it from there.

Java's abstraction of InputStreams (where the consumer need not know where the data is from) should make this very straightforward (assuming your audio library is not hard-coded to read from files).

Start by looking up ByteArrayOutputStream and ByteArrayInputStream.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜