Aframe video only plays muted on ios

断了今生、忘了曾经 提交于 2019-12-02 07:36:03

Webkit policy only allows video autoplay for silent videos. You need a user gesture like a tap on the screen to play videos with sound. Copying from the Webkit blog post for convenience:

A note about the user gesture requirement: when we say that an action must have happened “as a result of a user gesture”, we mean that the JavaScript which resulted in the call to video.play(), for example, must have directly resulted from a handler for a touchend, click, doubleclick, or keydown event. So, button.addEventListener('click', () => { video.play(); }) would satisfy the user gesture requirement. video.addEventListener('canplaythrough', () => { video.play(); }) would not.

The listener works (fires "it clicks_1") but the video dosnt start and it gives me this error : Unhandled Promise Rejection: NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission. HTML:

<a-image id="playbutton_1" class="clickable" position="-5 0 0" width="2" height="2" rotation="0 -90 0" foo></a-image>

js:

  AFRAME.registerComponent("foo", {
    init: function() {
      var playthisvid_1 = document.querySelector('#playbutton_1');
      var videoEl_1 = document.querySelector('#intro');

  playthisvid_1.addEventListener('click', () => {

        videoEl_1.play();
        console.log("it clicks_1");
      })
    }
  })
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!