tags:

views:

18

answers:

2

Hello all,

1) Is there a way in java to stream an audio file from ftp on my jsp page?

2) How can I play an audio file in jsp without audio file being download on client browser (like live stream) - temporary internet files

please help with some code example

A: 

Audio in a webbpage is usually to be included by the HTML <embed> element (which uses the platform default player) or the HTML <object> element (wherein you can specify a more specific player for which the webbrowser can eventually automagically download the necessary plugin software). See also this w3schools tutorial.

Either way, it should point to an URL which returns the audio stream. This can be just a static file in the public webcontent, next to the JSP file. E.g. http://example.com/context/file.wav. But when the audio file is stored outside the public webcontent or in a database, then you'd like to stream it via a Servlet. Basically just get an InputStream of it (using e.g. FileInputStream) and then write it to the OutputStream of the response along a correct set of response headers.

Noted should be that JSP is irrelevant in this particular question. It's just a view technology providing a template to write HTML in and send it to the webbrowser.


That said, websites which plays audio are generally considered annoying and generally scare off visitors. Keep this in mind if you consider User Experience important.

BalusC
thnx for your replay I doing exactly what you're suggesting here, my concern is to some how avoid the audio file of being downloaded on client's machine (IE-Temporary Internet Files) , if you use embed tag it downloads the entire file first,is there a way of avoiding this file download
slimshady
Instead of the poor man's `<embed>`, use the `<object>` element and specify a player with settings supporting streaming audio. You can find [here](http://www.google.com/search?q=html+object+streaming+audio) several examples.
BalusC
A: 

Streaming audio from a file does not have anything to do with the JSP itself.

You want to embed your audio file into the page using HTML tags. You can do this directly like:

<embed src="audiofile.mp3">

Or build something a bit more fancy using a Flash movie as an audio player, or find a JavaScript library. Here is a page on how to do it with various methods.

The JSP can provide the audio file name and perhaps other options, but that's all it has to do -- the rest is handled by plain old HTML tags.

You can find more information by searching the Web for the terms "embed" and "audio".

Jeff