Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

programmatic play() not working Chrome Android #4288

Closed
coryc5 opened this issue Apr 18, 2017 · 5 comments
Closed

programmatic play() not working Chrome Android #4288

coryc5 opened this issue Apr 18, 2017 · 5 comments

Comments

@coryc5
Copy link

coryc5 commented Apr 18, 2017

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:
#3428

versions

videojs

5.19.1

browsers

Chrome for Android 56

OSes

Android

@varemenos
Copy link

This might be related to #3131

@misteroneill
Copy link
Member

misteroneill commented Apr 18, 2017

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.

@leoafarias
Copy link

@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/

@luckyluggi
Copy link

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

This made it work for me.

@gkatsev
Copy link
Member

gkatsev commented Dec 4, 2017

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.

@gkatsev gkatsev closed this as completed Dec 4, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants