Stream refreshed media for playback and view full
This commit is contained in:
+29
-9
@@ -1080,13 +1080,15 @@
|
||||
body.className = `vk-media-viewer ${vertical ? "vertical" : "wide"}`;
|
||||
media.replaceChildren();
|
||||
|
||||
const source = item.localUrl || item.thumbUrl || item.url;
|
||||
const direct = item.localUrl || (item.source !== "embed" ? item.url : null);
|
||||
const playableFile = !!direct && /\.(mp4|webm|m4v)(\?|$)/i.test(direct);
|
||||
// The stream endpoint serves the local file or a refreshed remote URL, so signed
|
||||
// CDN links that expired no longer break playback.
|
||||
const streamUrl = `/api/media/${item.scrapeId}/${item.itemId}/stream`;
|
||||
const source = item.localUrl || item.thumbUrl || streamUrl;
|
||||
const embed = embedUrlFor(item);
|
||||
const canPlay = !!embed || playableFile;
|
||||
const directVideo = item.localUrl || item.playUrl || (item.source !== "embed" ? streamUrl : null);
|
||||
const canPlay = !!embed || (item.kind === "video" && !!directVideo);
|
||||
|
||||
// A play request on something we cannot embed falls back to the external page.
|
||||
// A play request on something we cannot play falls back to the external page.
|
||||
if (play && !canPlay) openLinkWarning(item.url);
|
||||
|
||||
if (play && embed) {
|
||||
@@ -1095,11 +1097,25 @@
|
||||
frame.allow = "autoplay; fullscreen; picture-in-picture";
|
||||
frame.allowFullscreen = true;
|
||||
media.append(frame);
|
||||
} else if (play && playableFile && direct) {
|
||||
} else if (play && directVideo) {
|
||||
const video = document.createElement("video");
|
||||
video.controls = true;
|
||||
video.autoplay = true;
|
||||
video.src = direct;
|
||||
video.src = directVideo;
|
||||
video.addEventListener(
|
||||
"error",
|
||||
() => {
|
||||
media.replaceChildren(
|
||||
el("div", "vk-media-status", "This format is not supported in the browser.")
|
||||
);
|
||||
media.append(
|
||||
button("Open in new tab", () =>
|
||||
window.open(directVideo, "_blank", "noreferrer")
|
||||
)
|
||||
);
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
media.append(video);
|
||||
} else if (/^(https?:|\/)/.test(source)) {
|
||||
const img = document.createElement("img");
|
||||
@@ -1127,8 +1143,12 @@
|
||||
link.addEventListener("click", () => openLinkWarning(item.url));
|
||||
meta.append(link);
|
||||
|
||||
// "View full" opens the embedded media (player, local file, or preview) in a new tab.
|
||||
const fullUrl = embedUrlFor(item) ?? item.localUrl ?? item.thumbUrl ?? item.url;
|
||||
// "View full" opens the embedded media (player, local file, or a refreshed stream).
|
||||
const streamPath = `/api/media/${item.scrapeId}/${item.itemId}/stream`;
|
||||
const fullUrl =
|
||||
embedUrlFor(item) ??
|
||||
item.localUrl ??
|
||||
(item.kind === "video" ? streamPath : item.playUrl ?? item.thumbUrl ?? streamPath);
|
||||
meta.append(button("View full", () => window.open(fullUrl, "_blank", "noreferrer")));
|
||||
|
||||
viewerModal.hidden = false;
|
||||
|
||||
Reference in New Issue
Block a user