Video object playback in Safari?

Safari block videos from being played if they have an audio track and are not launched by a user gesture. Unfortunately, clicking once on the game is not sufficient. The play() function has to be called from a “onClick” or other JavaScript callback. This is not the case in GDevelop: events are run outside of a JavaScript callback.

See this article explaining how it works: New <video> Policies for iOS | WebKit (" WebKit’s New policies for video" section)

Potential solution:

  • Workaround: remove the audio track from the video, so that it’s not blocked by safari. This means audio must be launched separately.
  • Workaround that we could put in GDevelop: set the video to be muted, if Safari is detected, so that Safari plays it. But this would basically transform the issue into “video sound is not working on Safari”.
  • Find a way to start the video by doing a hack: when a video is tried to be played, but the play method promise is rejected, we register a “onMouseDown”/“onTouchDown” on the document that will play the video (not sure if that would work, but your get the idea). This means that the video will be launched one frame too late. Not a huge deal, but can create some confusion if you try to check with a condition if the video is playing immediately after using the action to play.

EDIT: would be great to make an issue on GitHub to follow this up.

1 Like