如何通过点击按钮asp.net播放声音? [英] how to play sound by clicking button in asp.net?

查看:259
本文介绍了如何通过点击按钮asp.net播放声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  如何发挥在asp.net网页中的声音?

我试图通过点击按钮来播放声音。但它不玩这个声音。它曾经扮演另一种声音。
我不想使用绝对地址,我需要使用相对地址。
这是我的code

hi I'm trying to play a sound by click button .but it doesn't play this sound .it plays another sound ever. I don't want to use absolute address I need to use relative address. this is my code

 protected void Button1_Click1(object sender, EventArgs e)
    {

       System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
       System.IO.Stream s = a.GetManifestResourceStream("chimes.wav");
       SoundPlayer player = new SoundPlayer(s);
       player.Play();       
    }

在的S这个code值为NULL,我不知道为什么。

in this code value of s is always NULL and I don't know why.

推荐答案

您必须在code,关于服务器和code上的客户端浏览器上运行运行区分。

You must distinguish between the code that run on server and the code that run on client browser.

在code你必须写在这里是试,以在服务器上运行,即使它的运行,IT经理将开始听到咔哒声,而不是用户。

The code you have write here is "try" to run on server, and even if its run, the IT manager will start hear "clicks" and not the user.

您可以看看这个答案 http://stackoverflow.com/a/12329209/159270 从previous同样的问题,并尝试了解不同的声音必须在客户端浏览器上玩,而不是在服务器上。

You can look this answer http://stackoverflow.com/a/12329209/159270 from your previous same question and try to understand the different, the sound must be played on clients browser, not on server.

,你也可以阅读这个问题的答案有关的更多详细信息:<一href=\"http://stackoverflow.com/questions/10648471/how-to-play-audio-and-video-files-in-web-browser\">How在Web浏览器中播放音频和视频文件?

and also you can read this question answer with more details about: How to play audio and video files in web browser?

这篇关于如何通过点击按钮asp.net播放声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆