开发者

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

开发者 https://www.devze.com 2023-02-01 15:49 出处:网络
I\'m trying to play a WAV file that I generate dynamically in a HTTP handler and settin开发者_StackOverflow社区g the NavigateUrl property of HyperLink control:

I'm trying to play a WAV file that I generate dynamically in a HTTP handler and settin开发者_StackOverflow社区g 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"
0

精彩评论

暂无评论...
验证码 换一张
取 消