From 78d5b1893decae252c806f46fa45d07112da4897 Mon Sep 17 00:00:00 2001 From: Bigard Florian Date: Wed, 19 Jul 2017 14:07:52 +0200 Subject: [PATCH] Fix player on embed --- client/src/standalone/videos/embed.html | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/client/src/standalone/videos/embed.html b/client/src/standalone/videos/embed.html index 365dc3fa2..d4bb74263 100644 --- a/client/src/standalone/videos/embed.html +++ b/client/src/standalone/videos/embed.html @@ -71,7 +71,7 @@ xhttp.send() } - function loadVideoTorrent (magnetUri) { + function loadVideoTorrent (magnetUri, player) { console.log('Loading video ' + videoId) var client = new window.WebTorrent() @@ -79,7 +79,19 @@ client.add(magnetUri, function (torrent) { var file = torrent.files[0] - file.renderTo('video', { autoplay: true }) + file.renderTo('video', function (err) { + if (err) { + console.error(err) + return + } + + // Hack to "simulate" src link in video.js >= 6 + // If no, we can't play the video after pausing it + // https://github.com/videojs/video.js/blob/master/src/js/player.js#L1633 + player.src = function () { return true } + + player.play() + }) }) } @@ -127,13 +139,11 @@ }) document.querySelector('.vjs-big-play-button').addEventListener('click', function () { - loadVideoTorrent(magnetUri) - - player.play() + loadVideoTorrent(magnetUri, player) }, false) }) }) - +