Well put! Thanks

My requirement is to have a web page where people can 'sample' our content before purchasing... I have a flash page that plays the MP3, getting the mp3 via a URL.

My servlet then picks the 'sample' data from my database and passes it back to the flash player. So I still need to think of some way to get 5 seconds from the MP3.

Thanks
Jeff

Ben van der Merwe wrote:


Come to think of it, given the nature of compressed files, I can't imagine a method of accurately capturing 5 seconds of play than to actually play the mp3 for 5 seconds while directing the output to a file sink or memory buffer.

Ben van der Merwe wrote:
It would depend on the sampling rate of the particular mp3 (e.g. a 256khz MP3 could be *very* roughly 2 times bigger than a 128khz).

MP3's are obviously also compressed. Violin music would contain more seconds of play in the first 20k bytes than modern rock (signal to noise ratio ;)

Cheers,
Ben

jeff wrote:

Thanks for the reply Michael.

That is what I have done at the moment, but the issue I have is that some songs would then play for 1 second, some for 10 seconds. All depends on the song I suppose.

Maybe I did it incorrectly, I just took the first 20 000 bytes for example from the byte[]. Would it make a difference if I only read 20 000 bytes from the stream?

Cheers
Jeff

Michael Wiles wrote:
If it's only mp3's you're looking for then a quick and dirty approach is
to just retrieve X bytes of the mp3. mp3's are streamed so if you
truncate them you can still play them, they're just shorter. You'd have
to experiment to see how many bytes would give you about 5 seconds.

You could probably take a similar approach with a lot of sound files,
Waves for instance.

-----Original Message-----
From: jeff [mailto:[EMAIL PROTECTED] Sent: 19 January 2006 03:45 PM
To: [email protected]
Subject: [CTJUG Forum] MP3 / Audio Truncation


Hi All

I need to get the first 5 seconds of an MP3 or any sound file for that matter.

My MP3's are stored as byte[] in a database. Having looked at a number of different java API's (well only sound and JMF really) and not having

any experience with any java media coding, I am hoping someone can point

me in the right direction.....even some code sample :) would be nice.

Thanks in advance
Jeff










Reply via email to