简体   繁体   English

asp.net从后面的代码播放声音文件

[英]asp.net playing sound file from code behind

I have a page that calculates certain values coming from a web service. 我有一个页面,用于计算来自Web服务的某些值。

I would like to be able to play different sounds based on the calculation results. 我希望能够根据计算结果播放不同的声音。 There must be no interaction from the user (click button to play). 用户不得进行任何交互(单击按钮进行播放)。

The SoundPlayer class seems like what I need but I believe there is an error with the relative path because if I specify the absolute path it does work. SoundPlayer类似乎是我所需要的,但我相信相对路径存在错误,因为如果我指定绝对路径,它将起作用。

System.Media.SoundPlayer playthewavfile = new System.Media.SoundPlayer(@"Sounds\sound1.wav");
playthewavfile.Play();

The Sounds folder is in the root of the website. “声音”文件夹位于网站的根目录中。

我会尝试使用Server.MapPath将其拉出

System.Web.HttpContext.Current.Server.MapPath(path);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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