Safari & Starling: videos playing not allowed

Hi guys,

On safari I have the error:

Unhandled Promise Rejection: [object DOMError]

When trying to play a video.

Searching on the internet, it seems to be related to video autoplay restriction…

Videos with sound are bloqued on Safari (from the last version)…when condidered as “autoplay”

EDIT : even videos without sounds :rage:

How do you handle this issue?

In my scenario, the video is not auto playing : the user needs to touch the lauch button (that is not in the same Class as the video player), but Safari considers it’s an autoplay!

Edit : even if the touch event is in the same Class :face_with_symbols_over_mouth:

I am using Starling VideoTexture.
The error occurs when I call play() on my netStream:

_ns.play(_asset_url);

How can I do to make Safari understand that?

Thanks for your help! :slight_smile:

Perhaps try using a normal MouseEvent from the OpenFL stage, not from Starling. Starling has an event queue for touch events, which disconnects the user action of tapping from the call stack that later calls your listener code.

I’ve seen similar problems with pop-ups being blocked, but only from Starling events

Thanks for your answer singmajesty.

Unfortunatly, I encounter the same issue with OpenFL stage MouseEvent…

 private function showVideo() : Void
 {
    _nc = new NetConnection();
	_ns = new NetStream(_nc);
	
	var client:Dynamic = {}; 
	client.onMetaData = onMetaData;
	_ns.client = client;
		
	_asset_url = Assets.getPath(_url);
		
	_texture = Texture.fromNetStream(_ns, 1, onTextureReady);
		
	addClickEvent();
}

private function addClickEvent() 
{
	Starling.current.nativeStage.addEventListener(MouseEvent.CLICK, onClick);
}

private function onClick(e:MouseEvent):Void 
{
	_ns.play(_asset_url); // Error in Safari
}

That is really annoying because I have two Starling AIR apps to convert to HTML5…and both use video.
And Chrome is going to put the same restriction as Safari starting in january 2018…

No idea of what I can try now :thinking:

Do you need sound from your video? It seems that lifts the restriction

Otherwise, I think this will require deeper investigation into when the error is provided, and how it can be worked around

https://webkit.org/blog/7734/auto-play-policy-changes-for-macos/

It sounds like we should at least try to handle this error condition, and not crash out the application, if there’s a way to treat it in a better way

No, I don’t need sound in this case, but even with a video with no sound at all, the error occurs… :frowning:

I think Safari needs the HTML “muted” param to autoplay videos…

This is a big issue for me as I will not be able to deliver the website without video…

And it’s a big issue for everyone who wants to work with OpenFL Starling because it meens no video possible…

Maybe try adding __video.muted = true in here on your install?

https://github.com/openfl/openfl/blob/develop/openfl/net/NetStream.hx#L54

See if that helps?

OK, I will try it after wy week vacation…

Thanks for your help singmajesty!

1 Like

OK, adding

__video.muted = false;

allow video to be played on Safari! :slight_smile:

But I think this remains a big issue if we can’t play anymore video with sound in Safari (and maybe soon Chrome)… I hope there will be a fix soon.

Thanks again for your help singmajesty! :+1:

I also noticed that the fix works if the file extension is “.mp4” but it dispatches error if file extension is “.f4v”…
If I simply rename the file that’s ok…