Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro JSP
|
Pro JSP Advanced JSP coding questions. Beginning questions will be redirected to the Beginning JSP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro JSP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 23rd, 2009, 01:42 AM
Registered User
 
Join Date: Nov 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem playing mp3 from database in jsp page

Hi,
I have searched a lot and at last found this forum,and i think i can find my solutions here......

Q->I have stored all my songs in my oracle database my db table is like this...CREATE TABLE SONGS_TABLE(title varchar2(20),songs BLOB); .
Creating an admin page in jsp (insertSongs.jsp) i have inserted my data into the songs_table .And then in another jsp page (i.e songsList.jsp)
i have query for displaying only songs list from db code below............................................. ......................
String QueryString = "SELECT title from mysong";
rs = statement.executeQuery(QueryString);
%>


<%
while (rs.next()) {
String arr[]= new String [rs.getString("title").split("\\,").length];
int i;
for(i=0;i<arr.length;i++)
{
arr = rs.getString("title").split("\\,");

%>
<a href="Player.jsp?sid=<%=rs.getString("title")%>" ><input TYPE=checkbox NAME="chkSample" VALUE="<%=rs.getString("title")%>" ><%=rs.getString("title")%></a><BR>


<% } } %>
<%
// close all the connections.

rs.close();
statement.close();
connection.close();
} catch (Exception ex) {
%>
.................................................. .....................

Now My Problem is that how to play that songs or a list of songs on clicking on it to a swf player ie in my Player.jsp page.............................................. .....................................

String QueryString = "SELECT * from mysong where title='"+request.getParameter("sid")+"'";
rs = statement.executeQuery(QueryString);
%>
<%
while (rs.next()) {
byte[] bytearray = new byte[10240];
int size=0;

InputStream songs;

//response.addHeader("Content-Disposition","filename=getsongs.mp3");
response.reset();
response.setContentType("audio/mpeg");
songs=rs.getBinaryStream(2);


while((size=songs.read(bytearray))!= -1)
{
response.getOutputStream().write(bytearray,0,size) ;
}
//response.flushBuffer();


%>

<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="obj1" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" border="0" width="160" height="160">
<param name="movie" value="Player.swf">
<param name="src" value="<%=%>" >
<param name="quality" value="High">
<embed src="Player.swf" SRC="<%=%>" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="obj1" width="160" height="160">
</object>


<%songs.close(); %>
<% } %>
<%
// close all the connections.

rs.close();
statement.close();
connection.close();
} catch (Exception ex) {
%>
.................................................. ........................

My exact problem is that how to feed the songs or songs list to a swf player from database directly?
have i to create any dynamic .xml file or else for songs list to a swf player? if so how?
 
Old November 29th, 2009, 01:55 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

You can try by writing a servlet/jsp which takes song title as parameter and reads the data from the db and writes to response object. Use this servlet's URL in 'SRC' attribute of the swf player 'object/embed' tag.

Which means 'Player.jsp' in the above code has to be splitted to two jsps.
Hope it works :-)
__________________
- Rakesh
http://iam-rakesh.blogspot.com
 
Old November 30th, 2009, 07:51 AM
Registered User
 
Join Date: Nov 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default hi

hi rakesh,
Thanks for ur suggestion? can u describe with code according to my code above?
i m waitnig for some one,s reply since 2 week?

thanks
 
Old November 30th, 2009, 09:54 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

May be somethings like the below code

Code:
Player.jsp
<html>
<head>Playing song</head>
<body>
<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="obj1" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" border="0" width="160" height="160">
<param name="movie" value="Player.swf">
<param name="src" value="playsong.jsp?title=<%=request.getParameter("sid")%>" >
<param name="quality" value="High">
<embed src="Player.swf" SRC="playsong.jsp?title=<%=request.getParameter("sid")%>" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="obj1" width="160" height="160">
</object>

</body>
</html>
Code:
playsong.jsp

<%
String QueryString = "SELECT * from mysong where title='"+request.getParameter("sid")+"'";
rs = statement.executeQuery(QueryString);
%>
<%
while (rs.next()) {
byte[] bytearray = new byte[10240];
int size=0;

InputStream songs;

//response.addHeader("Content-Disposition","filename=getsongs.mp3");
response.reset();
response.setContentType("audio/mpeg");
songs=rs.getBinaryStream(2);


while((size=songs.read(bytearray))!= -1)
{
response.getOutputStream().write(bytearray,0,size) ;
}
//response.flushBuffer();


%>

<%songs.close(); %>
<% } %>
<%
// close all the connections.

rs.close();
statement.close();
connection.close();
} catch (Exception ex) {
%>
I didn't modified your code, just split your jsp code in to two, i guess you can do lot of cleanup :-)

Do try it and let me know whether it works or not!
__________________
- Rakesh
http://iam-rakesh.blogspot.com
 
Old December 1st, 2009, 01:59 AM
Registered User
 
Join Date: Nov 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Thanks

Hi
Rakesh Thanks for ur frequent response,I am trying as u said,and i think it shold be work in this way but i dnt know when i am running this program as u write code above by simple modifying it dont work.The player.jsp comes a swf player with nothing playing only player but in the url it showing request which i send...

please understanding this use help me..

Thanks
bikash





Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent,Plz help...Problem with playing wav msg Andisheh C# 2005 0 July 5th, 2007 04:43 AM
playing a movie in a web page jameee ASP.NET 2.0 Professional 2 September 17th, 2006 04:19 PM
how to access the database within same jsp page [email protected] Pro JSP 0 April 5th, 2006 06:48 AM
Connect Jsp Page To Sql Server Database jayul_p3nt JSP Basics 1 January 22nd, 2006 10:17 AM
Manipulating data in a database - page 396 problem Jams30 BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 October 17th, 2003 03:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.