RE: Datagrid Hyperlink field to play file system wave file help.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Morris,

From your description, I understand your web application will display some
links 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.


.



Relevant Pages

  • RE: Datagrid Hyperlink field to play file system wave file help.
    ... links on one page and the link will point to some wav sound ... As for the media file, how do you want to play it to client user, ... As for the wav file linking problem, I don't think we can directly use the ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Sound linking problems - still
    ... I read up on linking and embedding when I first discovered this prob. ... I even went into the laptop of another person not hearing the wav and increase her kb to 2000kb, ... That means that the file should play fine in PowerPoint on that system. ... >> receipiants via email can't hear the sound. ...
    (microsoft.public.powerpoint)
  • Re: 2 questions to add sound
    ... Changing the label won't change the contents. ... BUT try that method of renaming sound file in Microsoft Media Player ... that to play the sound. ... does then I could convert it into .wav and paste it into my other .wav file or ...
    (microsoft.public.powerpoint)
  • Re: embeded wav plays in PP editor but will not play from PP Playe
    ... Is there a reason that you didn't use Insert> Movies and Sounds> Sound ... That's the way to embed the WAV. ... >> When you right click on the speaker icon on your slide and select "Edit Sound ... After saving the PP Presentation I tried to play the ...
    (microsoft.public.powerpoint)
  • Play embedded non-WAV sounds without COM components?
    ... The subject says it all really, but to emphasise that I don't wan't to play ... and the sound file must be ... I could only get it to work with WAV files. ... Write my own managed code to convert the embedded WMA to WAV on-the-fly ...
    (microsoft.public.dotnet.framework)