vycxexra8: Play feed videos from hlsUrl with a thumbnail fallback
This commit is contained in:
+17
-1
@@ -5,6 +5,8 @@ export interface CardMedia {
|
||||
kind: "image" | "video";
|
||||
/** Image source (images) or poster (videos). May be null for a bare video. */
|
||||
src: string | null;
|
||||
/** Mux HLS playlist (videos only). Null when the video is not ready yet. */
|
||||
hlsUrl?: string | null;
|
||||
}
|
||||
|
||||
export interface CardPost {
|
||||
@@ -47,6 +49,18 @@ function authorName(author: Obj): string {
|
||||
return full || "Unknown";
|
||||
}
|
||||
|
||||
/** The HLS URL only when it is https on stream.mux.com. */
|
||||
export function muxHlsUrl(v: unknown): string | null {
|
||||
const s = str(v);
|
||||
if (!s) return null;
|
||||
try {
|
||||
const u = new URL(s);
|
||||
return u.protocol === "https:" && u.hostname === "stream.mux.com" ? s : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function toMedia(raw: unknown): CardMedia[] {
|
||||
if (!Array.isArray(raw)) return [];
|
||||
const items = raw
|
||||
@@ -56,7 +70,9 @@ function toMedia(raw: unknown): CardMedia[] {
|
||||
const out: CardMedia[] = [];
|
||||
for (const { m } of items) {
|
||||
if (m.mediaType === "video") {
|
||||
out.push({ kind: "video", src: str(m.thumbnailUrl) });
|
||||
const thumb = str(m.thumbnailUrl);
|
||||
const hls = muxHlsUrl(m.hlsUrl);
|
||||
if (thumb || hls) out.push({ kind: "video", src: thumb, hlsUrl: hls });
|
||||
continue;
|
||||
}
|
||||
const src = str(m.imageMediumWebpUrl) ?? str(m.imageMediumUrl) ?? str(m.imageUrl);
|
||||
|
||||
Reference in New Issue
Block a user