简体   繁体   中英

C#/ASP.NET - Play dynamically generated WAV file on client click

I'm trying to play a WAV file that I generate dynamically in a HTTP handler and setting the NavigateUrl property of HyperLink control:

<asp:HyperLink runat="server" NavigateUrl="~/ServeAudio.ashx" Text="Play Sound" ImageUrl="~/images/speaker_louder_32.png"
                        ToolTip="Play Sound"></asp:HyperLink>

But when I click on that link, it opens Windows Media Player - I don't want that. I just want the sound to play.

I have also tried using a few of the jQuery plugins and they seem to work if I have have a fixed URL to a WAV file but they don't work if I set the URL to my HTTP handler.

Any ideas? Thanks in advance.

Use an HTTP analyser like Fiddler or browser development tools like Firebug (or dev tools on IE) to see what HTTP headers are sent when you are accessing the WAV file directly.

Then mimic the HTTP headers from your handler by setting the them using HttpResponse.AppendHeader Method . Possibly something like this:

Response.AppendHeader("Content-Type", "audio/x-wav");

Another trick that might help is to craft the url, so it looks like a file (you should not need this if you can use the appropriate HTTP headers):

"~/ServeAudio.ashx/my.wav"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM