如何使用c#在在线Web应用程序中的特定时间播放声音 [英] How to play a sound on specific time in online web application using c#
问题描述
我想在在线网络应用程序中添加警报概念
I want to add alarm concept in online web application
推荐答案
您可以只播放音频文件。使用HTML5,您可以使用音频
元素。
这是显示控件和自动的最简单代码 - 开始播放:
You can just play an audio file. With HTML5, you can use theaudio
element.
This is the simplest code where you show controls and auto-start the play:
<audio controls="controls" autoplay="autoplay">
<source src="music.mp3" />
</audio>
可能,你不想要控制和自动播放。没有自动播放有点棘手:你需要省略属性; autoplay =false
将无效(!)
如果要隐藏它,则需要属性隐藏
。最后,我将展示如何隐藏控件并开始使用JavaScript。这是我能提出的最简单的样本:
Probably, you don't want the control and auto-play. No auto-play is a bit tricky: you need to omit the attribute; autoplay="false"
won't work (!)
If you want to hide it, you need the attribute hidden
. And finally, I'll show how to hide the controls and start playing by JavaScript. This is the simplest sample I could come up with:
<html>
<head>
<title>Play audio</title>
</head>
<body>
<audio hidden="hidden" id="au">
<source src="sound.mp3" />
</audio>
<button id="play">Play</button>
<script>
var au = document.getElementById("au");
var play = document.getElementById("play");
play.onclick = function() { au.play(); }
</script>
</body>
</html>
当然,此处的按钮仅用于说明。据我了解,您的目标是通过计时器事件来播放它。原理是一样的。
请参阅: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio [ ^ ]。
如果你不想依赖HTML5(我不知道为什么),你可以使用旧垃圾,如对象
和嵌入
元素。相信我,这个过时的东西并不好玩。例如,参见 http://web.cortland.edu/flteach/mm-course/sound -embedding.html [ ^ ]。
Naturally, the button here is just for illustration. As I understand, you are aimed to play it by the timer event. The principle is the same.
Please see: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio[^].
And if you don't want to rely on HTML5 (I don't know why), you can use old trash like object
and embed
elements. Believe me, this obsolete stuff is no fun. See, for example, http://web.cortland.edu/flteach/mm-course/sound-embedding.html[^].
这篇关于如何使用c#在在线Web应用程序中的特定时间播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!