【问题标题】:Video HTML5 on iOS : Autoplay with sound on click onlyiOS 上的视频 HTML5:仅在点击时自动播放声音
【发布时间】:2017-04-18 09:12:38
【问题描述】:

我尝试在我的网站上集成一个视频 (MP4),它会在没有声音的情况下自动启动(自动播放),但是当您单击视频放大观看时,您必须能够有声音。

我做不到,是禁止的吗?

PS:我读到这个:https://webkit.org/blog/6784/new-video-policies-for-ios/

使用下面的这段代码,自动播放可以工作,但是当我点击视频时,iPad 上没有声音。

<video id="video-autoplay" src="videos/animaux_720x404.mp4" autoplay muted controls="controls" playsinline>
     Votre navigateur ne supporte pas les vidéos au format HTML5.<br>
     Veuillez mettre à jour votre navigateur ou utilisez Mozilla Firefox.
  </video>

【问题讨论】:

    标签: ios html audio video autoplay


    【解决方案1】:

    尝试使用它来切换muted 属性。

    $("video").click( function (){
        $(this).prop("muted", !$(this).prop("muted"));
    });
    

    另请参阅 this post 了解 iOS 上的功能或官方 Apple doc on HTMLMediaElement

    【讨论】:

    • 我尝试了类似的方法: var maVideo = document.getElementById("video"); maVideo.addEventListener("点击", function(){ maVideo.removeAttribute("静音"); });但它不起作用,就像你的代码一样:(
    猜你喜欢
    • 2023-03-31
    • 2019-12-14
    • 1970-01-01
    • 2018-05-28
    • 1970-01-01
    • 1970-01-01
    • 2011-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多