如何发挥在asp.net网页中的声音? [英] how to play a sound in asp.net web page?
问题描述
我想在我的网页播放一些声音,一旦我点击一个按钮。
这是我的code,但它显示了一个错误。
I want to play some sounds in my web page once I click a button . this is my code but it shows an error.
SoundPlayer x = new SoundPlayer();
x.SoundLocation = "WindowsBalloon.wav";
//x.Play();
x.PlaySync();
错误:请务必声音文件存在于指定位置
error: Please be sure a sound file exists at the specified location.
但该文件在我的项目存在。而我敢肯定,该地址是正确的。
but the file exists in my project .and I'm sure that the address is correct.
推荐答案
使用网页上不能播放文件的<一个href=\"http://msdn.microsoft.com/en-us/library/system.media.soundplayer.aspx\">System.Media.Soundplayer类!!!
You cannot play a file on a web page using the System.Media.Soundplayer class !!!
这将播放声音在服务器端没有客户端。
It will play sound on server-side not client-side.
由于在下面的链接中提到结果
- <一个href=\"http://www.dreamin$c$c.net/forums/topic/27846-problem-with-the-c%23-systemmediasoundplayer-class-on-a-web-host/\">Problem与C#System.Media.SoundPlayer级上的Web主机结果
- <一个href=\"http://stackoverflow.com/questions/5775832/what-is-the-most-compatible-way-of-autoplaying-sound/5775984#5775984\">What是自动播放声音最兼容的方式?
As mentioned as in below links
- Problem With The C# System.Media.SoundPlayer Class On A Web Host
- What is the most "compatible" way of autoplaying sound ?
- 使用 ASP.NET音频控制。
- 答案在同样的要求。
- 使用任何其他基于Flash或Silverlight插件。
- 使用HTML嵌入标签或HTML5音频标记。例如可以在 W3Schools的 可见
- Use ASP.NET audio control.
- Other SO Answer over this same requirements.
- Use Any other Flash or Silverlight based plugins.
- Use html embed tag or html5 audio tag. Examples can be seen on w3schools
-
&LT;嵌入&GT;
标记:在&LT;嵌入&GT;
标记定义外部的(非HTML容器)的含量。 (这是一个HTML5标签,在HTML 4无效,但在所有浏览器上运行)。
<embed>
tag: The<embed>
tag defines a container for external (non-HTML) content. (It is an HTML5 tag, invalid in HTML 4, but works in all browsers).
<embed height="100" width="100" src="horse.mp3" />
-
&LT;对象&gt;
标记:在&LT;对象&gt;
标签还可以定义外部容器(非-HTML)的含量。 <object>
tag: The<object>
tag can also define a container for external (non-HTML) content.
<object height="100" width="100" data="horse.mp3"></object>
-
&LT;音频&GT;
标记:在&LT;音频&GT;
元素是一个HTML5元素,在HTML 4无效,但它工作在所有浏览器。 <audio>
tag: The<audio>
element is an HTML5 element, invalid in HTML 4, but it works in all browsers.
<audio controls="controls" height="100" width="100">
<source src="horse.mp3" type="audio/mp3" />
<source src="horse.ogg" type="audio/ogg" />
<embed height="100" width="100" src="horse.mp3" />
</audio>
请注意使用基于HTML5的解决方案,您必须将视频转换为不同的格式的问题。结果
- 在&LT;音频&GT;
元素不验证为HTML 4和XHTML结果
- 在&LT;&嵌入GT;
元素不验证为HTML 4和XHTML结果
- 在&LT;&嵌入GT;
元素不能回退,以显示错误。
Please note the problems with html5-based solutions you must convert your videos to different formats.
- The <audio>
element does not validate as HTML 4 and XHTML.
- The <embed>
element does not validate as HTML 4 and XHTML.
- The <embed>
element cannot "fall-back" to display an error.
这篇关于如何发挥在asp.net网页中的声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!