.net中如何播放声音
用做监控程序中,当某个事件触发时播放指定的声音文件(如:alarm.wav)。
请大虾们帮帮忙啊!
------解决方案--------------------如果是WEB项目,可以考虑使用JS/FLASH播放器
------解决方案--------------------<embed src="..." loop="true"></embed>
用一个这样的标签就可以了。。。
------解决方案--------------------
刚好一个项目中有相同的需求,代码如下
JScript code
<script type="text/javascript">
<!--
GetAlertInfoCount = function(){
$.ajax({
type:"GET",
dataType:"html",
url:"usercontrol/CheckAlertMessage.ashx",
data:"",
cache:false,
success:function(data){
if(data>0){
$("#alertInfoMessage").show();
if($("#alertInfoCount").text()!=data)
{
document.getElementById("alertInfoMessage").innerHTML="";
document.getElementById("alertInfoMessage").innerHTML="<span>有"+data+"条报警信息!</span><embed src='images/HOOK.WAV'hidden='true'autostart='true'loop='false'>";
$("#alertInfoCount").text(data);
}
$("#alertInfoMessage").css({color:"red",cursor:"pointer","font-size":"12px"});
$("#alertInfoMessage").click(
function(){
goURL("AlarmInfo/AlarmLog.aspx");
$("#alertInfoMessage").hide();
}
);
}else{
$("#alertInfoMessage").hide();
}
}
});
var MyMar=setTimeout(GetAlertInfoCount,60000); //一分钟刷新一次
}
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
internal static System.IO.UnmanagedMemoryStream A{
get {
return ResourceManager.GetStream("A", resourceCulture);
}
}
private void playSound()
{
System.Media.SoundPlayer simpleSound = new System.Media.SoundPlayer(Properties.Resources.A);
simpleSound.Play();
}
[DllImport("winmm.dll")]
public static extern long PlaySound(String fileName,long a,long b);
ASP.NET
Response.Write(@"<bgsound src='' loop='1'/>");
<EMBED src="" width=144 height=60
border=0 autostart=true loop=true> </EMBED>
引用SoundPlayer
System.Media.SoundPlayer sndPlayer = new System.Media.SoundPlayer("");
sndPlayer.PlayLooping();
用Microsoft speech object Library
public void PlaySound(string FileName)
{
if (!System.IO.File.Exists(FileName))
{
return;
}
SpeechLib.SpVoiceClass pp = new SpeechLib.SpVoiceClass();
SpeechLib.SpFileStreamClass spFs = new SpeechLib.SpFileStreamClass();
spFs.Open(FileName, SpeechLib.SpeechStreamFileMode.SSFMOpenForRead, true);
SpeechLib.ISpeechBaseStream Istream = spFs as SpeechLib.ISpeechBaseStream;