Solved

Servlet to play .wav or .dss file at the browser end

Posted on 2004-09-27
10
1,120 Views
Last Modified: 2008-02-01
I am using JBoss server and deployed a J2EE application in RedHat Linux. I created a .jar file and placed in the deploy folder of the JBoss Server. From any servlet that is deployed, "/" becomes the root of the jar file and but not the local disk "/". Now, I have local audio files (.dss, .wav) , for example say at location "/home/audiofiles/". I have to play them at the client end. I am a novice to Java Servlets ... Please help me out ! Thanks in advance.
0
Comment
Question by:cmallela
  • 4
  • 4
10 Comments
 

Author Comment

by:cmallela
ID: 12183773
Please help me experts !!! I have increased the points !!!
0
 
LVL 3

Expert Comment

by:applekanna
ID: 12186157
Hi cmallela,
I think the server can identify between the paths absolute as well as relative. Did u try it,
I have tried it in other instance to read text files and it works fine without any problem.
Chck the path again

Cheers!
0
 
LVL 2

Expert Comment

by:siliconeagle
ID: 12356258
you need to open the file and sent it to the cilent if it not in the media files aren't in the document tree of the webserver.

either
1. move the media files into the docRoot of the webserver then you can just make links to them. this is easiest. You can probably put them all in another app if all else fails and just deploy it if you cant find the docRoot of the webserver.
2. read the file and output it using a servlet making sure you set the appropriate content type.
0
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 

Author Comment

by:cmallela
ID: 12422874
Dear Expert,

                          The first solution I tried. It recognized .wav as an audio file but .dss as a html file. When I directly give the url of dss file (eg. http://23.19.198.299:...../3782992.dss) it just displays some garbled data, when I directly give the url of wav file (eg. http://23.19.198.299:...../72898292.wav), it opens windows media player and played the file.

                           The second solution (probably the best for me, coz there are large number of files to copy into docRoot of webserver), I dont know how to write it up. Can you help me with the steps ?

Please help me.. Its getting urgent.

Thanks.
0
 
LVL 3

Accepted Solution

by:
applekanna earned 250 total points
ID: 12424655
dss....

did u try add it in the mime type in your web.xml file
http://www.developer.com/java/ent/print.php/10933_3343761_2

Also try this
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 6.00.2900.2180" name=GENERATOR></HEAD>
<BODY>
<OBJECT id=mediaPlayer
codeBase="http://activex.microsoft.com/activex/ controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"
type=application/x-oleobject
standby="Loading Microsoft Windows Media Player components..."
classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95><PARAM NAME="fileName" VALUE="AmazingGracewithBagpipes-BackdraftTheme.mp3"><PARAM NAME="animationatStart" VALUE="true"><PARAM NAME="transparentatStart" VALUE="true"><PARAM NAME="autoStart" VALUE="true"><PARAM NAME="showControls" VALUE="true"></OBJECT>
<p>Plays Bagpiper Grace Music
</BODY></HTML>

this loads the media player in IE... try to chae it for DSS in whichver player it plays ......



No offense here :)
but
>>Please help me.. Its getting urgent.
you need to be more active
post 1 = 9/29
post 2 = 10/27

CHeers!
0
 

Author Comment

by:cmallela
ID: 12427449
Dear applekanna,

             Thank you so much for the suggestion. I tried it and it worked but I have so many files that are on the hard drive of the server. I dont have any files that are in the docroot of the web server. I have to play the files that are not in the docroot of the webserver. I dont know how to refer to the path of the files that are not in the docroot of the server. I can do the following -

                a) I can either dynamically copy the required dss file into the docroot of the webserver based on the request from the client and then play it.

                                           OR

                b) I have to write a servlet that directly links the client's request to the file that is residing on the server (path which I dont know how to give ?!?!)

                I dont know if there is any best solution but for the thoughts I have, I dont know how to do it. Please help me.

Thanks.
0
 
LVL 3

Expert Comment

by:applekanna
ID: 12431571
>> I tried it and it worked but I have so many files that are on the hard drive of the server

Glad it worrked. Curous to knwo as to what worked - mime type???

>>a) I can either dynamically copy the required dss file into the docroot of the webserver based on the request from the client and then play it.

not a good idea.

Only files from the doc root can be accessed by the user.
If you want to deliver files you need to read it in a stream and then write out.

If you want to give the direct path without having  the trouble of reading it then you have to place it in the doc root.

code snippet for reading and wrirint a stream
*************
    String CONTENT_TYPE = "dss";
    String fullPathFileName = "/usr/local/music/dss/britney.dss"

    response.setContentType(CONTENT_TYPE);
    //open the file input stream  and read the contents in a stream..
    System.out.println("the filename for trenda dats is " + fullPathFileName);
    File downloadFile = new File(fullPathFileName);
    FileInputStream fin = new FileInputStream(downloadFile);
    response.setHeader("Content-Disposition", "attachment;filename="+fileName);
    BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
    byte b[] = new byte[(int)downloadFile.length()];
    int read = 0;
    while((read = fin.read(b)) != -1)
    {
    bos.write(b,0,read);
    }
    bos.flush();
    fin.close();
    bos.close();


*************

Hope this helps...
Cheers !!!
0
 

Author Comment

by:cmallela
ID: 12436068
yes - the mime type worked.

I tried the code snippet you gave me but at the browser end, I was prompted for a download / cancel of a file. I downloaded it but it was not the dss file. It was some File with no extension.

However, in the code snippet you gave me,

>>    response.setHeader("Content-Disposition", "attachment;filename="+fileName);

I replaced fileName with fullPathFileName .. is that correct ?

Also, is there a way to automatically play the file, instead of the download prompt ??

Thanks for all your help.
0
 
LVL 3

Expert Comment

by:applekanna
ID: 12437678
>>I replaced fileName with fullPathFileName .. is that correct

the filename should be exact file name - eg say shakeer.dss
in the download prompt , it will say what file you want to download as "shakira.dss"

it will also solve your "file with no extension" problem

>>Also, is there a way to automatically play the file, instead of the download prompt ??

yes there is ..but i havent tried it yet....
but if you use the servlet I am not sure.

I shall also search ...

Cheers
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maven project import to eclipse problems 13 105
constuctor calling other constructor 2 76
spring AOP 6 86
Looking for some programs to resell or buy source codes 1 77
This tutorial shows how to create a greeting card by combining two image layers and a text layer on a PC using a free image editing app.
This article outlines the process to identify and resolve account lockout in an Active Directory environment.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question