2022-04-14 22:12:30 +08:00
|
|
|
<script lang="ts">
|
2023-06-08 11:54:02 +08:00
|
|
|
import { createEventDispatcher, afterUpdate, tick } from "svelte";
|
2023-03-30 07:30:00 +08:00
|
|
|
import { BlockLabel, Empty, IconButton } from "@gradio/atoms";
|
2022-04-14 22:12:30 +08:00
|
|
|
import type { FileData } from "@gradio/upload";
|
2023-03-30 07:30:00 +08:00
|
|
|
import { Video, Download } from "@gradio/icons";
|
2022-04-14 22:12:30 +08:00
|
|
|
|
2022-07-06 00:30:02 +08:00
|
|
|
import Player from "./Player.svelte";
|
|
|
|
|
2022-04-14 22:12:30 +08:00
|
|
|
export let value: FileData | null = null;
|
2023-04-12 07:06:48 +08:00
|
|
|
export let subtitle: FileData | null = null;
|
2022-04-14 22:12:30 +08:00
|
|
|
export let label: string | undefined = undefined;
|
2023-06-29 02:37:21 +08:00
|
|
|
export let show_label = true;
|
2023-06-09 07:27:58 +08:00
|
|
|
export let autoplay: boolean;
|
|
|
|
|
2023-04-12 07:06:48 +08:00
|
|
|
let old_value: FileData | null = null;
|
|
|
|
let old_subtitle: FileData | null = null;
|
2022-04-14 22:12:30 +08:00
|
|
|
|
|
|
|
const dispatch = createEventDispatcher<{
|
|
|
|
change: FileData;
|
|
|
|
play: undefined;
|
|
|
|
pause: undefined;
|
2023-06-08 11:54:02 +08:00
|
|
|
end: undefined;
|
|
|
|
stop: undefined;
|
2022-04-14 22:12:30 +08:00
|
|
|
}>();
|
|
|
|
|
|
|
|
$: value && dispatch("change", value);
|
2023-04-12 07:06:48 +08:00
|
|
|
|
|
|
|
afterUpdate(async () => {
|
|
|
|
// needed to bust subtitle caching issues on Chrome
|
|
|
|
if (
|
|
|
|
value !== old_value &&
|
|
|
|
subtitle !== old_subtitle &&
|
|
|
|
old_subtitle !== null
|
|
|
|
) {
|
|
|
|
old_value = value;
|
|
|
|
value = null;
|
|
|
|
await tick();
|
|
|
|
value = old_value;
|
|
|
|
}
|
|
|
|
old_value = value;
|
|
|
|
old_subtitle = subtitle;
|
|
|
|
});
|
2022-04-14 22:12:30 +08:00
|
|
|
</script>
|
|
|
|
|
2022-05-10 08:26:09 +08:00
|
|
|
<BlockLabel {show_label} Icon={Video} label={label || "Video"} />
|
2022-04-27 18:47:15 +08:00
|
|
|
{#if value === null}
|
2023-06-08 20:24:13 +08:00
|
|
|
<Empty unpadded_box={true} size="large"><Video /></Empty>
|
2022-04-27 18:47:15 +08:00
|
|
|
{:else}
|
|
|
|
<!-- svelte-ignore a11y-media-has-caption -->
|
2023-06-07 05:49:04 +08:00
|
|
|
{#key value.data}
|
|
|
|
<Player
|
|
|
|
src={value.data}
|
|
|
|
subtitle={subtitle?.data}
|
2023-06-09 07:27:58 +08:00
|
|
|
{autoplay}
|
2023-06-07 05:49:04 +08:00
|
|
|
on:play
|
|
|
|
on:pause
|
|
|
|
on:ended
|
|
|
|
mirror={false}
|
2023-06-29 02:37:21 +08:00
|
|
|
{label}
|
2023-06-07 05:49:04 +08:00
|
|
|
/>
|
|
|
|
{/key}
|
2023-03-30 07:30:00 +08:00
|
|
|
<div class="download" data-testid="download-div">
|
|
|
|
<a
|
|
|
|
href={value.data}
|
|
|
|
target={window.__is_colab__ ? "_blank" : null}
|
|
|
|
download={value.orig_name || value.name}
|
|
|
|
>
|
|
|
|
<IconButton Icon={Download} label="Download" />
|
|
|
|
</a>
|
|
|
|
</div>
|
2022-04-27 18:47:15 +08:00
|
|
|
{/if}
|
2023-03-30 07:30:00 +08:00
|
|
|
|
|
|
|
<style>
|
|
|
|
.download {
|
|
|
|
position: absolute;
|
|
|
|
top: 6px;
|
|
|
|
right: 6px;
|
|
|
|
}
|
|
|
|
</style>
|