RE: Datagrid Hyperlink field to play file system wave file help.
- From: stcheng@xxxxxxxxxxxxxxxxxxxx (Steven Cheng[MSFT])
- Date: Thu, 24 Aug 2006 12:12:39 GMT
Hi Morris,
From your description, I understand your web application will display somelinks on one page (through grid) and the link will point to some wav sound
so that the user can play it when click on the link. The problem is that
the wav files is in a non-virtual directory(accessible through http
address) on the server, correct?
As for this problem, I think it is doable and have several means. I'd like
to confirm following things first:
1. Are you developing through ASP.NET 1.1/VS 2003 or ASP.NET 2.0/VS 2005?
2. As for the media file(wav), how do you want to play it to client user,
among the following options:
** let the client user directly link to the media and the browser will
choose a player on the client to play it.
** embed some activex or sound tag in web page and use let the browser to
play it, thus , the client will not launch a separate player when user
click the link.
As for the wav file linking problem, I don't think we can directly use the
physical path(like c:\media\.....) because this path is not recommend for
internet application. also, the "c:\media\" physical path is only valid to
the server machine, since the page is finally displayed in client browser,
the browser will try locating the file on the client machine's disk and
won't be able to get the file.
To resolve this, I suggest you consider the following means:
1)Create an ASP.NET web page or HttpHandler which will programmtically read
the file from the non-web folder and then write it out as response stream.
e.g.
suppose the page's name is "MediaOutput.aspx", we add the following code in
its code behind:
==================
public partial class MediaOutput : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string fn = Request.QueryString["fn"];
if (string.IsNullOrEmpty(fn))
{
throw new Exception("Invalid Argument...........");
}
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "audio/wav";
Response.WriteFile(@"D:\temp\media\" + fn);
Response.End();
}
}
============================
Then, in other page which want to reference a certain wav file in the
"D:\temp\media" folder, we no longer need to care about the physical path,
but simply use the "MediaOutput.aspx" to get the wav stream. e.g.
<a href="MediaOutput.aspx?fn=ding.wav" >play ding.wav </>
if you want to create a custom httphandler to do the work, please refer to
the following article:
http://weblogs.asp.net/cazzu/archive/2003/08/27/25568.aspx
However, as I've mentioned, if you directly point to the wav stream in the
hyperlink, the wav will be played in a new player window at
client-side(maybe media player or other player...). If you do not want to
let a new launched player to do it, you can have a look at the following
web pages:
#Playing Sounds On The Web
http://www.w3schools.com/media/media_browsersounds.asp
#Demonstration of Different Ways to Play a Sound from a Web Page
http://www.phon.ucl.ac.uk/home/mark/audio/play.htm
it demonstrate several means to play sound, you can even use javascript to
make a certain element(like <bgsound> or <embed> to reference the media
stream output by the "mediaoutput.aspx" page above).
Hope this helps. If there is anything unclear, please feel free to let me
know.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
.
- Follow-Ups:
- RE: Datagrid Hyperlink field to play file system wave file help.
- From: Morris Neuman
- RE: Datagrid Hyperlink field to play file system wave file help.
- Prev by Date: Re: ASP.net hosting?
- Next by Date: Re: State not working properly -- sessions and ASP.NET 2.0 Profiles
- Previous by thread: Re: HTTPModule and ISAPI
- Next by thread: RE: Datagrid Hyperlink field to play file system wave file help.
- Index(es):
Relevant Pages
|