Spaces:
Running on Zero
Running on Zero
Restore inline playback when Gradio updates an existing player
Browse files- assets/playback.js +11 -7
assets/playback.js
CHANGED
|
@@ -6,12 +6,12 @@ function inlinePlayback(monitor, playButton) {
|
|
| 6 |
let attemptId = 0;
|
| 7 |
|
| 8 |
function configure(video) {
|
| 9 |
-
video.playsInline = true;
|
| 10 |
-
video.setAttribute("playsinline", "");
|
| 11 |
-
video.setAttribute("webkit-playsinline", "");
|
| 12 |
if (video.closest("#live-feed")) {
|
| 13 |
-
video.defaultMuted = true;
|
| 14 |
-
video.muted = true;
|
| 15 |
}
|
| 16 |
}
|
| 17 |
|
|
@@ -64,10 +64,14 @@ function inlinePlayback(monitor, playButton) {
|
|
| 64 |
sync();
|
| 65 |
}
|
| 66 |
|
| 67 |
-
const events = ["loadstart", "loadedmetadata", "canplay", "playing"];
|
| 68 |
events.forEach(name => monitor.addEventListener(name, onMedia, true));
|
| 69 |
const observer = new MutationObserver(sync);
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
playButton.addEventListener("click", playLive);
|
| 72 |
sync();
|
| 73 |
|
|
|
|
| 6 |
let attemptId = 0;
|
| 7 |
|
| 8 |
function configure(video) {
|
| 9 |
+
if (!video.playsInline) video.playsInline = true;
|
| 10 |
+
if (!video.hasAttribute("playsinline")) video.setAttribute("playsinline", "");
|
| 11 |
+
if (!video.hasAttribute("webkit-playsinline")) video.setAttribute("webkit-playsinline", "");
|
| 12 |
if (video.closest("#live-feed")) {
|
| 13 |
+
if (!video.defaultMuted) video.defaultMuted = true;
|
| 14 |
+
if (!video.muted) video.muted = true;
|
| 15 |
}
|
| 16 |
}
|
| 17 |
|
|
|
|
| 64 |
sync();
|
| 65 |
}
|
| 66 |
|
| 67 |
+
const events = ["loadstart", "loadedmetadata", "canplay", "playing", "volumechange"];
|
| 68 |
events.forEach(name => monitor.addEventListener(name, onMedia, true));
|
| 69 |
const observer = new MutationObserver(sync);
|
| 70 |
+
// The Gradio player can also reapply its defaults to an existing video.
|
| 71 |
+
observer.observe(monitor, {
|
| 72 |
+
childList: true, subtree: true, attributes: true,
|
| 73 |
+
attributeFilter: ["playsinline", "webkit-playsinline", "muted"]
|
| 74 |
+
});
|
| 75 |
playButton.addEventListener("click", playLive);
|
| 76 |
sync();
|
| 77 |
|