V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
metalbug
V2EX  ›  HTML

是否能判断 HTML5 视频里有没有音频?

  •  
  •   metalbug · Aug 1, 2017 · 3980 views
    This topic created in 3195 days ago, the information mentioned may be changed or developed.

    一段没有音频的视频,怎么判断它有没有音频?

    a570295535
        1
    a570295535  
       Aug 1, 2017
    我的耳朵是出气的。。。
    Tonni
        2
    Tonni  
       Aug 1, 2017   ❤️ 2
    方案: https://stackoverflow.com/a/23399773/4480674
    缺点:浏览器兼容性不够好
    metalbug
        3
    metalbug  
    OP
       Aug 1, 2017
    @Tonni 谢啦
    metalbug
        4
    metalbug  
    OP
       Aug 1, 2017
    <!DOCTYPE html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="https://code.jquery.com/jquery-1.11.3.js"></script>
    </head>
    <body>
    <video autoplay loop id="myVideo">
    <source src="http://www.leoog.com/wp-content/uploads/2017/07/leoog_13934734.mp4" type="video/mp4">
    </video>
    <video autoplay loop id="myVideo">
    <source src="http://www.runoob.com/try/demo_source/mov_bbb.mp4" type="video/mp4">
    </video>
    <script type="text/javascript">
    document.getElementById("myVideo").addEventListener("loadeddata", function() {
    if (typeof this.webkitAudioDecodedByteCount || this.mozHasAudio || this.audioTracks !== "undefined") {
    if (this.webkitAudioDecodedByteCount > 0 || this.mozHasAudio || this.audioTracks && this.audioTracks.length)
    this.after("有声");
    else
    this.after("没声");
    }
    });
    </script>
    </body>
    </html>

    @Tonni 这段 JS 可以,但是多个视频怎么写?新手求大神赐教。
    metalbug
        5
    metalbug  
    OP
       Aug 1, 2017
    搞好了可以关贴了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   845 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 19:42 · PVG 03:42 · LAX 12:42 · JFK 15:42
    ♥ Do have faith in what you're doing.