Skip to content

Commit

Permalink
use render_media component for both audio and video elements
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Nov 11, 2024
1 parent e11a937 commit 9a7f6e2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@
import { env } from '@env';
import Spinner from './Spinner.svelte';
export let sessionId: String;
export let filename: String;
async function getSignedURL() {
const blobname = `${BLOB_BASE_URI}/${sessionId}`;
const blobname = `${BLOB_BASE_URI}/${filename}`;
return fetch(`${env.API_BASE_URL}/get-signed-url?blobname=${blobname}`).then<string>((res) => {
if (res.ok) return res.json();
throw new Error('Failed to get signed Audiocast URL');
});
}
</script>

{#await getSignedURL()}
<Spinner />
{:then audioURL}
<audio controls class="w-full animate-fade-in block">
<source src={audioURL} type="audio/mpeg" />
Your browser does not support the audio element.
</audio>
{:catch error}
<div>{String(error)}</div>
{/await}
<div class="w-full flex flex-col gapy-3">
{#await getSignedURL()}
<Spinner />
{:then uri}
<slot {uri} />
{:catch error}
<div>{String(error)}</div>
{/await}
</div>
3 changes: 2 additions & 1 deletion app/src/lib/components/Sidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
.map(([sessionId, item]) => ({
title: item.title || 'Untitled',
nonce: item.nonce,
href: `/chat/${sessionId}?category=${item.category}`
href: `/chat/${sessionId}?category=${item.category}`,
sessionId
}))
.sort((a, b) => b.nonce - a.nonce);
Expand Down
3 changes: 2 additions & 1 deletion app/src/lib/components/SidebarItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
title: string;
nonce: number;
href: string;
sessionId: string;
};
</script>

Expand All @@ -21,7 +22,7 @@
easing: cubicInOut
});
$: isActive = $page.url.href.includes(item.href);
$: isActive = $page.url.href.includes(item.sessionId);
</script>

<Button
Expand Down
2 changes: 2 additions & 0 deletions app/src/routes/audiocast/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { redirect } from '@sveltejs/kit';
export const load = () => redirect(307, '/');
31 changes: 23 additions & 8 deletions app/src/routes/audiocast/[sessionId=sessionId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import type { ContentCategory } from '@/utils/types';
import { env } from '@env';
import { parse } from 'marked';
import RenderAudiocast from '@/components/RenderAudiocast.svelte';
import * as Accordion from '@/components/ui/accordion';
import RenderMedia from '@/components/RenderMedia.svelte';
const { session$ } = getSessionContext();
Expand Down Expand Up @@ -52,9 +52,7 @@
}
</script>

<div
class="mx-auto flex h-full w-full max-w-full flex-col items-center overflow-hidden px-2 sm:max-w-xl sm:px-1 lg:max-w-3xl"
>
<div class="mx-auto flex h-full w-full pb-40 overflow-auto mt-6 flex-col items-center px-2 sm:px-1">
{#if $session$?.summary}
{@const { summary, category } = $session$}
{#await getAudiocast($session$.id, category, summary)}
Expand All @@ -64,10 +62,29 @@
{:then data}
{@const script = data.script}
{@const sourceContent = data.source_content}
<div class="flex w-full flex-col gap-y-3">
<RenderAudiocast sessionId={$session$.id} />
<div class="flex w-full px-4 flex-col gap-y-3 sm:max-w-xl lg:max-w-3xl max-w-full">
<RenderMedia filename="{$session$.id}.mp4" let:uri>
<audio controls class="w-full animate-fade-in block">
<source src={uri} type="audio/mpeg" />
Your browser does not support the audio element.
</audio>
</RenderMedia>

<Accordion.Root>
<Accordion.Item value="item-0">
<Accordion.Trigger>Show Waveform</Accordion.Trigger>
<Accordion.Content>
<RenderMedia filename="{$session$.id}.mp4" let:uri>
<video controls class="w-full h-64 animate-fade-in block">
<source src={uri} type="video/mp4" />
Your browser does not support the video element.

<track kind="captions" />
</video>
</RenderMedia>
</Accordion.Content>
</Accordion.Item>

<Accordion.Item value="item-1">
<Accordion.Trigger>Audio Transcript</Accordion.Trigger>
<Accordion.Content>
Expand All @@ -78,9 +95,7 @@
</div>
</Accordion.Content>
</Accordion.Item>
</Accordion.Root>

<Accordion.Root>
<Accordion.Item value="item-2">
<Accordion.Trigger>Source Content</Accordion.Trigger>
<Accordion.Content>
Expand Down

0 comments on commit 9a7f6e2

Please sign in to comment.