Video.js: programmatic play() not working Chrome Android

Created on 18 Apr 2017  路  5Comments  路  Source: videojs/video.js

Description

As of Chrome for Android 53, video autoplay is now allowed as long as the video is muted. I have found a scenario where autoplay will not work with video.js even if the video is muted.

Example:
https://jsfiddle.net/0u0x42ed/2/

Steps to reproduce

Explain in detail the exact steps necessary to reproduce the issue.

  1. Set the video's source tag src attribute programmatically via the videojs.src() API
  2. call play()

Results

Expected

The expected result is that the video plays.

Actual

The video does not play

Error output

Failed to execute 'play' on 'HTMLMediaElement': API can only be initiated by a user gesture.

Additional Information

This is not a problem on iOS and it is also not a problem when setting the source through HTML, see:
https://jsfiddle.net/0u0x42ed/6/

Even though there is an alternative way to achieve autoplay without the error, this is not an approach that works when you are serving a DASH video, given that programmatically setting the src is the only way that currently works with DASH as of videojs 5.10+, see:
https://github.com/videojs/video.js/issues/3428

versions

videojs

5.19.1

browsers

Chrome for Android 56

OSes

Android

Most helpful comment

You need to set 2 attributes for the video tag.
autoplay and muted

This made it work for me.

All 5 comments

This might be related to #3131

Yeah, it is definitely related to that issue.

Calling play() is not the same thing as autoplay. You will want to set the autoplay attribute on your <video> element or pass autoplay: true in Video.js options. The video will play in either case, as you can see in these JSBins:

EDIT: You will still see a console message because, at multiple points with autoplay on, Video.js will call play() internally. However, it shouldn't break anything.

@coryc5 I am not sure if this helps, but by calling the src before the ready it seems to do the trick.
https://jsfiddle.net/fyde0fp8/

You need to set 2 attributes for the video tag.
autoplay and muted

This made it work for me.

We have improved autoplay/muted support in the player greatly in the latest versions of v5 and v6. Though, v6 has some other extra fixes.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

borm picture borm  路  3Comments

dingyaguang117 picture dingyaguang117  路  4Comments

0xsven picture 0xsven  路  3Comments

pblasi picture pblasi  路  3Comments

kitsunde picture kitsunde  路  4Comments