File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Playing audio file from Servlet in Jsp page. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Playing audio file from Servlet in Jsp page." Watch "Playing audio file from Servlet in Jsp page." New topic
Author

Playing audio file from Servlet in Jsp page.

ruba ramesh
Greenhorn

Joined: Oct 15, 2012
Posts: 3
Hi,

I have audio files stored as blob in MySql DB. I woule like to play the audio files in JSP. To achieve this, song_id is passed as parameter to servlet. Servlet retrieves the blob from DB and writes the blob as bytes in OutputStream of response object of Servlet.


Problem is I am not able to play the song in JSP file.

Tried following ways to do it.

1. Used JPlayer.
2. Embedding audio player pointing to servlet' URL as src.

<object classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" id="player" width="200" height="300">
<param name="url" value="<%=request.getContextPath()%>" />
<param name="src" value="GetSongForPlay?song_id=49"/>
<param name="showcontrols" value="true" />
<param name="autostart" value="true" />
<embed src="<%=request.getContextPath()%>/GetSongForPlay?song_id=49" width="<%=200%>" height="<%=300%>"></embed>
</object>

3. Used HTML5 audio tag.


But, I am not successful in playing song. Song is of type of mp3 or wav.

Can anybody suggest how to approach this?


Thanks
Wayan Saryada
Ranch Hand

Joined: Feb 05, 2004
Posts: 105

ruba ramesh wrote:Hi,
3. Used HTML5 audio tag.
But, I am not successful in playing song. Song is of type of mp3 or wav.


Before using the servlet have you tried to only use local HTML file with the audio tag and load it to see if it is work outside the servlet environment. What browser are you use to run the HTML audio? Please make sure that your browser support the audio format.


Website: Learn Java by Examples
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Does Jplayer support such streaming? AFAIK the embedded file must exist somewhere as a complete file, like Flash content. I have never embedded streaming content.


SCJP, SCWCD.
|Asking Good Questions|
ruba ramesh
Greenhorn

Joined: Oct 15, 2012
Posts: 3
I Wayan Saryada wrote:
ruba ramesh wrote:Hi,
3. Used HTML5 audio tag.
But, I am not successful in playing song. Song is of type of mp3 or wav.


Before using the servlet have you tried to only use local HTML file with the audio tag and load it to see if it is work outside the servlet environment. What browser are you use to run the HTML audio? Please make sure that your browser support the audio format.




Hmm.. Good idea. I tried out. HTML 5 is supported by Google chrome. This http://www.w3schools.com/html/html5_audio.asp reveals it's supported in IE9 and Chrome for mp3.

Thanks for the suggestion.

Rupa
ruba ramesh
Greenhorn

Joined: Oct 15, 2012
Posts: 3
Amit Ghorpade wrote:Does Jplayer support such streaming? AFAIK the embedded file must exist somewhere as a complete file, like Flash content. I have never embedded streaming content.


https://groups.google.com/group/jplayer/tree/browse_frm/month/2010-07/4c49ec0990b48360?rnum=21&_done=/group/jplayer/browse_frm/month/2010-07?&pli=1&auth=DQAAAIIAAACprnU-2LIrrsbGHf2GRZMCzaDNkowdairlcH0RhoAkkm_PyS2AcxJCltRtZeX2367CVZrzcLlxJZ9wLr0HmT06tLZdaHDm5uBMlUQUXWPckF9t5uNd2whcIRaQNEAEpWR_xcvz2M6wXAxlvy668_chBAaOCbic0GVuJFJVY4gvclUN0qyZPFtN8cRXjuh_b7M&authuser=0

says it's possible to have streaming audio.

Thanks

Rupa
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61198
    
  66

This is not streaming audio. Whether the data exists as a file on the server, or is delivered by a servlet is moot at the client. The response looks the same.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Playing audio file from Servlet in Jsp page.