Javascript 如何处理音频视频html5中不存在的源代码?

Javascript 如何处理音频视频html5中不存在的源代码?,javascript,jquery,html,onerror,Javascript,Jquery,Html,Onerror,如何处理音频视频html5中不存在的源代码 我试过: 纯javascript <audio controls onerror="alert(1);"> <source src="http://somethingthatnotexist" type="audio/mpeg"> </audio> 但这对我来说很不利,因为: 我需要提供超过1个音频给我的客户 有这么多的播放器插件/库使用而不是 谢谢你的帮助。试试这个 <audio controls>

如何处理音频视频html5中不存在的源代码

我试过: 纯javascript

<audio controls onerror="alert(1);">
  <source src="http://somethingthatnotexist" type="audio/mpeg">
</audio>
但这对我来说很不利,因为:

  • 我需要提供超过1个音频给我的客户

  • 有这么多的播放器插件/库使用
    而不是

  • 谢谢你的帮助。

    试试这个

    <audio controls>
      <source id="my_audio" src="http://somethingthatnotexist" type="audio/mpeg">
    </audio>
    

    一种更简单和常见的方法是:

    <audio controls>
      <source src="http://somethingthatnotexist" type="audio/mpeg">
      Error with source file!
    </audio>
    
    
    源文件出错!
    

    如果由于某种原因无法播放音频文件,将显示包含的文本。(不是在警报中,而是在播放器GUI中)

    nice。非常感谢你。我会更新我的问题,这样你的答案会很清楚地针对像我一样遇到同样问题的每个人
    <audio controls>
      <source id="my_audio" src="http://somethingthatnotexist" type="audio/mpeg">
    </audio>
    
    $("#my_audio").on("error", function (e) {
      alert("Error with source file!");
    });
    
    <audio controls>
      <source src="http://somethingthatnotexist" type="audio/mpeg">
      Error with source file!
    </audio>