Solved

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

Posted on 2004-09-27
10
1,083 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
 

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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/&#10;&#9;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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now