minznerjosh / vast-player

Playback VAST creatives in a web browser.
MIT License
45 stars 32 forks source link

Unhandled Promise Rejection in Safari #7

Closed hwde closed 6 years ago

hwde commented 6 years ago

The Example doesn't play in Safari 11 on Mac, it print the following exception, any idea?

[Error] Unhandled Promise Rejection: NotAllowedError (DOM Exception 35): The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission. (anonyme Funktion) rejectPromise play tryToUnwrap (vast-player.js:2607) tryCatch (vast-player.js:2619) safelyResolveThenable (vast-player.js:2610) Promise (vast-player.js:2484) startAd (vast-player.js:889) callMethod (vast-player.js:227) (anonyme Funktion) (vast-player.js:2534) nextTick (vast-player.js:2774)

hwde commented 6 years ago

Further investigations: Safari requires "click to play", this Error is caused by autoplay. The following article explains how to handle it: http://2ality.com/2016/04/unhandled-rejections.html.

By adding a button with an onclick=... below the container I was able to start the video inside an onclick-Handler ... but player.startAd() still raises above handler. I had to poke behind the private with: player.private.player.video.play();

Maybe the eventhandler and an auto-click-to-play-button could be integrated somehow?

minznerjosh commented 6 years ago

I don't want to add a button in this library as it leaves the user interface entirely up to the user. However, it should be possible to modify the code so that player.private.player.video.play() is called synchronously from player.startAd(), which should allow the video to play as long as player.startAd() is called synchronously within a click handler.

However, just from looking at the code, I can't see where the async-ness would be sneaking in. Are you sure you were calling player.startAd() synchronously and not in a callback? For example:

element.onclick = () => {
  player.load('tag.xml').then(() => {
    player.startAd(); // won't work because this is an async callback.
  });
};

If you could post a jsfiddle that demonstrates your issue, I'd be happy to check it out!

hwde commented 6 years ago

You're right ... I've setup a fiddle here and it works well on Safari too. Sorry, my issue must be somewhere else.