mirror of
https://github.com/videojs/video.js.git
synced 2025-02-08 12:05:47 +02:00
fix: force autoplay in Chrome (#4804)
Chrome has started pausing autoplaying video elements when they are moved in the DOM. Here we need to make sure that if the video started autoplaying, after we move the element in the DOM we call play again. Fixes #4720.
This commit is contained in:
parent
409a13e1f6
commit
6fe7a9a3dd
@ -471,6 +471,8 @@ class Player extends Component {
|
||||
this.changingSrc_ = false;
|
||||
this.playWaitingForReady_ = false;
|
||||
this.playOnLoadstart_ = null;
|
||||
|
||||
this.forceAutoplayInChrome_();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2557,11 +2559,29 @@ class Player extends Component {
|
||||
if (value !== undefined) {
|
||||
this.techCall_('setAutoplay', value);
|
||||
this.options_.autoplay = value;
|
||||
this.ready(this.forceAutoplayInChrome_);
|
||||
return;
|
||||
}
|
||||
return this.techGet_('autoplay', value);
|
||||
}
|
||||
|
||||
/**
|
||||
* chrome started pausing the video when moving in the DOM
|
||||
* causing autoplay to not continue due to how Video.js functions.
|
||||
* See #4720 for more info.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
forceAutoplayInChrome_() {
|
||||
if (this.paused() &&
|
||||
// read from the video element or options
|
||||
(this.autoplay() || this.options_.autoplay) &&
|
||||
// only target desktop chrome
|
||||
(browser.IS_CHROME && !browser.IS_ANDROID)) {
|
||||
this.play();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set or unset the playsinline attribute.
|
||||
* Playsinline tells the browser that non-fullscreen playback is preferred.
|
||||
|
@ -36,6 +36,8 @@ class TechFaker extends Tech {
|
||||
|
||||
setMuted() {}
|
||||
|
||||
setAutoplay() {}
|
||||
|
||||
currentTime() {
|
||||
return 0;
|
||||
}
|
||||
@ -54,6 +56,9 @@ class TechFaker extends Tech {
|
||||
muted() {
|
||||
return false;
|
||||
}
|
||||
autoplay() {
|
||||
return false;
|
||||
}
|
||||
pause() {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user