This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Not sure whether this is the correct Forum to post this Question. Anyway, this is my problem.
I am streaming a Audio File from a URL and setting the HttpServletResponce with the streamed data as shown in the code below. My problem is, now I have to stream only the first 30 seconds of the audio file, and not the entire one..
How can i ammend the code to stream only the first 30 seconds of the audio file..
You would need to know how many bytes = 1 second of playtime for the audio file. Im not really sure how you would find this out. You would have to read about the format which the audio file is stored as. I know when I play mp3s some play at 120K a second, and others play at 180K a second. In my case with the mp3s, I would guess that mp3s have some kind of header info that tells the player how many Kb to read per second. If you are streaming an mp3, you would need to read up on how a mp3 stores that info in the header and then extract it. Then if you were able to find this information out, just keep a count of the number of bytes read so far, and stream in the ( num bytes in a second ) * 30.
By the way, this is just all speculation and I could be dead wrong.
Although I am curious as to how this would be done now that I think about it more... Please post up how you solve this problem if/when you do. [ January 12, 2007: Message edited by: Kenny Johnson ]
Just setup a timer in your streaming loop for 30 seconds and close the stream at the end. The technique of finding bytes used for 1 sec will not work coz it varies with every file/encoding. And I am not sure if you really need to manipulate the file using JMF. In that case its better to have all files as 30 sec bits instead which may not be viable.