Skip to content

Commit

Permalink
Improve autoplay
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel authored and daniel committed Jan 13, 2020
1 parent 15979fe commit 66b2d36
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions view/include/video.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,31 @@
}
try {
player.currentTime(<?php echo $currentTime; ?>);
player.play();
var promise = player.play();

if (promise !== undefined) {
promise.then(_ => {
// Autoplay started!
}).catch(error => {
// Show something in the UI that the video is muted
player.muted(true);
player.play();
});
}
} catch (e) {
setTimeout(function () {
player.currentTime(<?php echo $currentTime; ?>);
player.play();
var promise = player.play();

if (promise !== undefined) {
promise.then(_ => {
// Autoplay started!
}).catch(error => {
// Show something in the UI that the video is muted
player.muted(true);
player.play();
});
}
}, 1000);
}
}, 150);
Expand All @@ -196,11 +216,31 @@
player = videojs('mainVideo'<?php echo PlayerSkins::getDataSetup(); ?>);
}
try {
player.play();
var promise = player.play();

if (promise !== undefined) {
promise.then(_ => {
// Autoplay started!
}).catch(error => {
// Show something in the UI that the video is muted
player.muted(true);
player.play();
});
}
} catch (e) {
setTimeout(function () {
player.currentTime(<?php echo $currentTime; ?>);
player.play();
var promise = player.play();

if (promise !== undefined) {
promise.then(_ => {
// Autoplay started!
}).catch(error => {
// Show something in the UI that the video is muted
player.muted(true);
player.play();
});
}
}, 1000);
}
}, 150);
Expand Down

0 comments on commit 66b2d36

Please sign in to comment.