Solved

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

Posted on 2004-09-27
10
1,131 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best practices to work on a spring MVC project 1 126
JSONSerializer.toJSON in JSP generating error 8 81
maven j2ee examles 2 60
jsp insert to database example 2 46
If you are looking at this article, you have most likely been hit by some version of ransomware and are trying to find out if there is anything you can do, or what way you should react - READ ON!
This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 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