我有网页表单,当用户点击按钮并从本地设备选择文件并将其上传到我项目中的文件夹时,此文件传递html5的音频标签,并准备播放 我试过以下代码
<div class="col-sm-5">
<asp:Button ID="btnbrowse" runat="server" Text="Upload File"
CssClass="btn btn-success btn-block"
OnClick="btnbrowse_Click" />
</div>
和背后的代码
string fileName = System.IO.Path.GetFileName(FileUpload5.PostedFile.FileName);
if (fileName != null)
{
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Forms/Upload/" + fileName));
string PATH = System.IO.Path.Combine(Server.MapPath("~/Forms/Upload"), FileUpload5.PostedFile.FileName);
string Path = Server.MapPath(FileUpload5.FileName);
SoundPlayer playthewavfile = new SoundPlayer(PATH);
playthewavfile.SoundLocation = Path.ToString();
playthewavfile.SoundLocation = PATH.ToString();
playthewavfile.Play();
}
答案 0 :(得分:0)
这就是我播放 .WAV文件的方式,对我来说很好用!
FileUpload1.PostedFile.SaveAs(Server.MapPath("uploads/" + FileUpload1.PostedFile.FileName));
string path = System.IO.Path.Combine(Server.MapPath("uploads/"),
FileUpload1.PostedFile.FileName);
SoundPlayer s = new SoundPlayer(path);
s.Play();