Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro JSP
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
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?
Reply With Quote
  #2 (permalink)  
Old November 29th, 2009, 01:55 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
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
Reply With Quote
  #3 (permalink)  
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
Reply With Quote
  #4 (permalink)  
Old November 30th, 2009, 09:54 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
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
Reply With Quote
  #5 (permalink)  
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent,Plz help...Problem with playing wav msg Andisheh C# 2005 0 July 5th, 2007 05:43 AM
playing a movie in a web page jameee ASP.NET 2.0 Professional 2 September 17th, 2006 05:19 PM
how to access the database within same jsp page muthumari_p2003@yahoo.com Pro JSP 0 April 5th, 2006 07: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 04:13 PM



All times are GMT -4. The time now is 08:09 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.