【发布时间】:2014-07-30 10:12:22
【问题描述】:
我有以下代码,但我不确定出了什么问题。我们拥有音频文件的远程主机有问题吗?在Chrome中,有时播放有时不播放,不播放时,并不是说我的浏览器不支持音频格式。
<audio controls id="audio" style="display:none">
<source src="http://langcomplab.net/Honey_Gatherers_Master.mp3" type="audio/mpeg" />
Your browser doesn't support this audio format.
</audio>
<button id="button">Play</button>
<script type="text/javascript">
// run on page load
var button = document.getElementById('button');
var audio = document.getElementById('audio');
var onClick = function() {
audio.play(); // audio will load and then play
};
button.addEventListener('click', onClick, false);
</script>
更新:这真的很奇怪。在源代码部分我添加了
</html> tag for a block in Qualtrics but when I source my code using rich context editor the tags fade away. Any solution to this?
<html>
<body onload='Qualtrics.SurveyEngine.addOnload'>
<p>The next two stories will be the two stories presented auditorily. Please press the “Play Story” button now to hear an example auditory story. Be sure to adjust the volume of the device on which you are listening so that you can hear the auditory story clearly.</p>
<p> </p>
<div>
<audio controls="" id="audio1" style="display:none"><source src="http://langcomplab.net/Test_take2.mp3" style="width:50%" type="audio/mpeg" />Your browser doesn't support this audio format.</audio>
</div>
<div><button name="play" onclick="disabled=true" style="height:25px; width:200px" type="button">Play Story</button>
<p> </p>
</div>
</body>
</html>
P.S.:我在onload 部分中使用了正确的功能吗?
【问题讨论】:
-
我正在刷新它,但似乎在 chrome 上没有遇到您的问题
-
我真的不知道问题的根源是什么。 1 小时前它对我不起作用,现在它正在起作用。我不知道如何重新生成问题。
-
您的按钮在我的 iPad 上无法使用(音频文件似乎加载非常缓慢,并且在 0:00 时卡住了) Ps:
display:none在 iOS 上无法使用 -
Derek 我们还没有为移动系统设计。我们只专注于桌面。不过非常感谢你的评论。我会记住这一点。 P.S.:在 iPad 上有没有 display:none 的替代品?
标签: javascript html audio browser hosting