Skip to content

Commit

Permalink
site: add hls-video example url params
Browse files Browse the repository at this point in the history
  • Loading branch information
luwes committed Sep 21, 2024
1 parent f4adb76 commit fb03564
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
13 changes: 12 additions & 1 deletion examples/nextjs/app/hls-video/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ export const metadata: Metadata = {
title: 'HLS Video - Media Elements',
};

export default function Page() {
type PageProps = {
searchParams: {
autoplay: string;
muted: string;
preload: string;
};
};

export default function Page(props: PageProps) {
return (
<>
<section>
Expand All @@ -18,6 +26,9 @@ export default function Page() {
controls
crossOrigin=""
playsInline
autoPlay={props.searchParams?.autoplay}
muted={props.searchParams?.muted}
preload={props.searchParams?.preload}
suppressHydrationWarning
>
<track
Expand Down
17 changes: 14 additions & 3 deletions examples/nextjs/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dirname } from 'node:path';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import * as fs from 'node:fs/promises';
import type React from 'react';
Expand All @@ -17,8 +17,19 @@ export const metadata: Metadata = {
description: 'A collection of custom media elements for the web.',
};

const fileDir = dirname(fileURLToPath(import.meta.url));
const themeScript = await fs.readFile(`${fileDir}/theme-toggle.js`, 'utf-8');
// https://francoisbest.com/posts/2023/reading-files-on-vercel-during-nextjs-isr
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const nextJsRootDir = path.resolve(__dirname, '../')

function resolve(...paths: string[]) {
const dirname = path.dirname(fileURLToPath(import.meta.url))
const absPath = path.resolve(dirname, ...paths)
// Required for ISR serverless functions to pick up the file path
// as a dependency to bundle.
return path.resolve(process.cwd(), absPath.replace(nextJsRootDir, '.'))
}

const themeScript = await fs.readFile(resolve('theme-toggle.js'), 'utf-8');

export default async function RootLayout({
children,
Expand Down

0 comments on commit fb03564

Please sign in to comment.