Overcoming Chrome's autoplay policy

Issues when playing with WebRTC Player

Overcoming Chrome's autoplay policy

Postby admin » Tue Dec 11, 2018 10:58 am

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

Because of that policy, your WebRTC 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.

Here is the usual WebRTC player javascript, that gets executed when the page loads:

<script type="text/javascript">
webrtcPlayer = new UnrealWebRTCPlayer("remoteVideo", "livedemocam", "", "", "80", false, true, "tcp");

Note that webrtcPlayer.Play(); will call video element play() which may be prohibited by the policy. In this case you will not see the video until you click on a play button in the player.

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

If you have audio or audio+video, the player will start muted, and the user will need to manually unmute it, so you may not want to add a muted attribute.
First thing to consider is - maybe you don't need to start playing automatically at all? Maybe you don't need to call webrtcPlayer.Play(); when the page loads,
but you will provide a "Start playing" button on a webpage, that will call that function?

Otherwise, if you do need to start playing automatically, you can still do it without muting the player, but you need to make your user 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 WebRTC 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 WebRTC Player

Who is online

Users browsing this forum: No registered users and 1 guest