How to play a sound on an HTA file

眉间皱痕 提交于 2019-12-10 10:49:10

问题


Ive been searching the internet for a while now and no tutorial has explained how to play sound

<Audio autoplay>
<source src="sound.mp3" type="audio/mp3">
</Audio>

No errors are displayed but no sound plays either, all help is appreciated


回答1:


Just simply use bgsound element to play an audio file:

<bgsound src="audio.mp3">

You can also specify a number for loop attribute which indicates how many times the audio file is to be played.
If you want to play your sound whenever a particular event occurs (e.g. the user clicks on a button), remove the src attribute, and change the value of this attribute via your script whenever you need to play your sound. For example:

<bgsound>
<button onclick="playSound()">Play</button>
<script language="javascript">
function playSound()
{
    document.getElementsByTagName("bgsound")[0].src = "audio.mp3";
}
</script>


来源:https://stackoverflow.com/questions/49102617/how-to-play-a-sound-on-an-hta-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!