Detect if ios11 device is in low power mode to prevent bad UX on normally correctly autoplaying video

后端 未结 4 2060
轻奢々
轻奢々 2020-12-18 08:34

I am running into a huge issue with autoplaying videos on iOS11 devices (at least tested on iphone 7 ios 11.2.5 safari ).

When the change in policy about autoplaying

4条回答
  •  悲&欢浪女
    2020-12-18 09:16

    This event handler can be used.

    jwplayer().on('autostartNotAllowed')
    

    Fired when the player is configured to autostart but the browser's settings are preventing it.

    const videoElement = document.getElementById('myVideo');
    
    videoElement.addEventListener('autostartNotAllowed', (e) => {
      console.log(e)
      // message: "The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission."
      // name: "NotAllowedError"
      // reason: "autoplayDisabled"
    });
    
    videoElement.addEventListener('play', () => {
      // remove play UI
    });
    

提交回复
热议问题