【问题标题】:How to solve the non-playing audio in HTML in various browsers如何解决各种浏览器中HTML不播放音频的问题
【发布时间】:2014-06-10 03:26:23
【问题描述】:

我在各种浏览器中播放以下 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>&nbsp;</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="">&lt; id=&quot;audio3&quot; src=&quot;http://langcomplab.net/Honey_Gatherers_Master.mp3&quot; style=&quot;width:50%&quot; type=&quot;audio/mpeg&quot;&gt;Your browser does not support this audio format.</audio>

【问题讨论】:

    标签: javascript html audio getelementbyid qualtrics


    【解决方案1】:

    你可以用这个:

    <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();" />
    

    【讨论】:

    • 您能看到我的问题中的更新吗?谢谢。
    • 您是否允许加载内容?该栏应该有一条白线,显示 youtube 上加载的内容。
    • 是的。另外我不想使用 HTML5 音频播放设计。我想使用我自己的按钮,如问题所示。如何摆脱显示的默认播放器?
    • 我添加了 style="display:none",以及一个使用 javascript 播放它的按钮,基于它的 id。如果您有多个音频阅读器,您可能希望使用比“阅读器”更具体的 ID,但我以它为例。
    • 所以现在它有时播放音频,有时不在同一个浏览器中的原因,与音频文件的远程主机有关吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-29
    • 1970-01-01
    • 2011-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多