• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1216
  • Last Modified:

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

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
cmallela
Asked:
cmallela
  • 4
  • 4
1 Solution
 
cmallelaAuthor Commented:
Please help me experts !!! I have increased the points !!!
0
 
applekannaCommented:
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
 
siliconeagleCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
cmallelaAuthor Commented:
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
 
applekannaCommented:
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
 
cmallelaAuthor Commented:
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
 
applekannaCommented:
>> 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
 
cmallelaAuthor Commented:
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
 
applekannaCommented:
>>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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now