Better way to handle iOS Safari autoplay issues?

Hi there, I recently put in a fix for an issue my app was having where subscribers on iOS (Safari/Chrome) would not see the publisher’s video play when the publisher switched between webcam/screen share/etc… (using OpenVidu.initPublisher).

I “fixed” this issue by essentially calling video.play() on all videoElementCreated events and then catching the error on iOS and then retrying play() with the audio muted and showing a prompt.

This works, but calling play() on the video element feels kind of messy/hacky, since in most cases the video is already playing.

I was wondering if there was a better solution known to OpenVidu devs (besides using a native app for iOS)? I couldn’t find much from searching Google and the forums.

Thanks!

iOS doesn’t allow playing a video with audio without a user gesture. By default, if a video has audio, it will appear stopped (Troubleshooting / FAQ - OpenVidu Docs)

You will need to emulate a user gesture if you want to autoplay the video without interaction