• 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Streaming Audo File, need to Stream only 30 seconds

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

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..

Thanks for any insights,,
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
s mahen,

You can use the Java Media Framework API (JMF) to cut the first 30 seconds out of your media file, and stream those.

This API has methods to retrieve parts of media files (includes mp3), and to write media data to a stream.

This example comes very close to what you want to do:

Given an input media file, the object is to cut pieces from the file and generate an output file from that.


More info on Sun's website:
http://java.sun.com/products/java-media/jmf/

Regards, Jan
[ January 13, 2007: Message edited by: Jan Cumps ]
 
s mahen perera
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot for both comments... will try these out and let you guys know..
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jan Cumps
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeevan,
I have some remarks on your suggestion:

Just setup a timer in your streaming loop for 30 seconds and close the stream at the end.



Cutting a stream will not be liked by the browser plug-in playing the tune. It will most likely show an 'error while streaming' message, because there is no valid end to the stream.

In that case its better to have all files as 30 sec bits



This would require you to cut 30 seconds out of every audio file you host. The JMF solution works on the full audio file. And it gives a valid break after the 30 seconds.

Regards, Jan
 
reply
    Bookmark Topic Watch Topic
  • New Topic