Overcoming Chrome's autoplay policy

Issues when playing live broadcasts with Unreal HTML5 MSE player on a web page

Overcoming Chrome's autoplay policy

Postby admin » Fri Dec 14, 2018 2:26 pm

Recently Chrome (and Opera too) introduced an autoplay policy,
fully described at https://developers.google.com/web/updat ... cy-changes

Because of that policy, if your parameter boolAutoPlay is true, then your HTML5 MSE players MAY NOT start playing automatically, once the webpage loads.
This is because Chrome wants a "user gesture", such as a user clicking on a play button, before starting playing.
Chrome mainly fights with audio starting to play automatically, but this policy, unfortunately, may prevent video-only streams to start playing automatically as well.

The easiest way to fix it is to add muted attribute to your video element.
If you have video-only streams, that's the ultimate solution.

You can do it in the web page script:

<script type="text/javascript">
if ("MediaSource" in window && "WebSocket" in window)
RunPlayer("UnrealPlayer1", 800, 450, "", 5119, false, "webcam", "", true, true, 1, "", false);
document.getElementById("UnrealPlayer1_Video").muted = true;
document.getElementById("UnrealPlayer1").innerHTML = "Media Source Extensions or Websockets are not supported in your browser.";

or, you can do it directly in unreal_html5_player_script_v2.js

If you have audio or audio+video, the player will start muted, and the user will need to manually unmute it, by clicking on the volume button.
So you may not want to add a muted attribute.
So the good news is - you can still start playing automatically without muting the player, but your web user needs to "interact with your domain" first - that's how Chrome's autoplay policy works.
So, if a user manually navigates to your domain first, or clicks on a link that leads to your domain, for example, to the main webpage of your web app, where he/she needs to login, and then he/she will see a webpage (from your domain) with HTML5 MSE player, then you are OK. You don't need to add a muted attribute. Player will start automatically.
Site Admin
Posts: 1039
Joined: Fri Aug 21, 2009 10:13 am

Return to Playing with HTML5 MSE Player

Who is online

Users browsing this forum: No registered users and 0 guests