我在各种浏览器中播放以下mp3,有时播放,有时不播放。具体来说,现在它不再在Chrome中运行,但在Firefox中运行:
http://langcomplab.net/Most_Precious_Possession_Master.mp3
这是它的代码:
The second auditory story is titled, “The Most Precious Possession.” Press the “Play Story” button to begin listening to the story; after you have finished listening to the story, you will answer a set of questions about the story.
<div>
<audio id="audio3" src="http://langcomplab.net/Most_Precious_Possession_Master.mp3" style="width:50%">Canvas not supported</audio>
</div>
<p> </p>
<div><button name="play" onclick="disabled=true" style="height:25px; width:200px" type="button">Play Story</button></div>
这是JavaScript:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place Your Javascript Below This Line*/
var aud = document.getElementById('audio3');
this.questionclick = function(event,element){
if((element.type == "button") && (element.name == "play"))
{
aud.play();
}
}
});
所以我不知道解决办法。我正在使用Qualtrics创建音频调查。
更新:
尽管我将代码更改为以下代码,但这并不表示浏览器不支持此格式。我不确定我缺少什么。这是屏幕截图:
<audio controls="">< id="audio3" src="http://langcomplab.net/Honey_Gatherers_Master.mp3" style="width:50%" type="audio/mpeg">Your browser does not support this audio format.</audio>
最佳答案
您可以使用以下代码:
<div>
<audio controls>
<source src="http://langcomplab.net/Most_Precious_Possession_Master.mp3"type="audio/mpeg">
Your browser does not support this audio format.
</audio>
</div>
它可以在任何现代浏览器上运行(需要HTML5)。希望能有所帮助。
编辑:要使其与按钮一起使用,而不显示HTML5控件,可以使用:
The second auditory story is titled...
<div>
<audio controls id="reader" style="display:none">
<source src="http://langcomplab.net/Most_Precious_Possession_Master.mp3"type="audio/mpeg">
Your browser does not support this audio format.
</audio>
</div>
<input id="Play Story" type="button" value="Play Story" onclick="document.getElementById('reader').play();" />
关于javascript - 如何在各种浏览器中解决HTML中无法播放的音频,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24126475/