Share custom media player controls
This commit is contained in:
1 parent
764593254e
commit
356b43b59e
2 files changed
+12
-25
No files matched your search
@@ -258,7 +258,7 @@
|
|||||||
</video>
|
</video>
|
||||||
{/if}
|
{/if}
|
||||||
<MediaPlayerControls
|
<MediaPlayerControls
|
||||||
kind={kind}
|
{kind}
|
||||||
{currentTime}
|
{currentTime}
|
||||||
{duration}
|
{duration}
|
||||||
{playing}
|
{playing}
|
||||||
|
|||||||
@@ -1,15 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {
|
import { Activity, Maximize2, Minimize2, Pause, Play, RotateCcw, RotateCw, Volume2, VolumeX } from '@lucide/svelte'
|
||||||
Activity,
|
|
||||||
Maximize2,
|
|
||||||
Minimize2,
|
|
||||||
Pause,
|
|
||||||
Play,
|
|
||||||
RotateCcw,
|
|
||||||
RotateCw,
|
|
||||||
Volume2,
|
|
||||||
VolumeX,
|
|
||||||
} from '@lucide/svelte'
|
|
||||||
import type { Snippet } from 'svelte'
|
import type { Snippet } from 'svelte'
|
||||||
|
|
||||||
export type MediaPlayerKind = 'audio' | 'video'
|
export type MediaPlayerKind = 'audio' | 'video'
|
||||||
@@ -73,9 +63,7 @@
|
|||||||
endControls?: Snippet
|
endControls?: Snippet
|
||||||
} = $props()
|
} = $props()
|
||||||
|
|
||||||
const progress = $derived(
|
const progress = $derived(duration > 0 ? `${Math.min(100, Math.max(0, (currentTime / duration) * 100))}%` : '0%')
|
||||||
duration > 0 ? `${Math.min(100, Math.max(0, (currentTime / duration) * 100))}%` : '0%',
|
|
||||||
)
|
|
||||||
const displayVolume = $derived(muted ? 0 : Math.min(1, Math.max(0, volume)))
|
const displayVolume = $derived(muted ? 0 : Math.min(1, Math.max(0, volume)))
|
||||||
const label = $derived(kind === 'audio' ? 'audio' : 'video')
|
const label = $derived(kind === 'audio' ? 'audio' : 'video')
|
||||||
|
|
||||||
@@ -121,7 +109,7 @@
|
|||||||
class="media-player-control"
|
class="media-player-control"
|
||||||
aria-label={playing ? `Pause ${label}` : `Play ${label}`}
|
aria-label={playing ? `Pause ${label}` : `Play ${label}`}
|
||||||
title={playing ? 'Pause (K or Space)' : 'Play (K or Space)'}
|
title={playing ? 'Pause (K or Space)' : 'Play (K or Space)'}
|
||||||
disabled={disabled}
|
{disabled}
|
||||||
onclick={onTogglePlayback}
|
onclick={onTogglePlayback}
|
||||||
>
|
>
|
||||||
{#if playing}<Pause class="media-player-icon-large" />{:else}<Play class="media-player-icon-large" />{/if}
|
{#if playing}<Pause class="media-player-icon-large" />{:else}<Play class="media-player-icon-large" />{/if}
|
||||||
@@ -132,7 +120,7 @@
|
|||||||
class="media-player-control media-player-seek-button"
|
class="media-player-control media-player-seek-button"
|
||||||
aria-label="Rewind 10 seconds"
|
aria-label="Rewind 10 seconds"
|
||||||
title="Rewind 10 seconds (Left Arrow)"
|
title="Rewind 10 seconds (Left Arrow)"
|
||||||
disabled={disabled}
|
{disabled}
|
||||||
onclick={() => onSkip?.(-10)}><RotateCcw class="media-player-icon" /></button
|
onclick={() => onSkip?.(-10)}><RotateCcw class="media-player-icon" /></button
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
@@ -140,7 +128,7 @@
|
|||||||
class="media-player-control media-player-seek-button"
|
class="media-player-control media-player-seek-button"
|
||||||
aria-label="Skip forward 10 seconds"
|
aria-label="Skip forward 10 seconds"
|
||||||
title="Skip forward 10 seconds (Right Arrow)"
|
title="Skip forward 10 seconds (Right Arrow)"
|
||||||
disabled={disabled}
|
{disabled}
|
||||||
onclick={() => onSkip?.(10)}><RotateCw class="media-player-icon" /></button
|
onclick={() => onSkip?.(10)}><RotateCw class="media-player-icon" /></button
|
||||||
>
|
>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -152,7 +140,7 @@
|
|||||||
class="media-player-control"
|
class="media-player-control"
|
||||||
aria-label={muted ? `Unmute ${label}` : `Mute ${label}`}
|
aria-label={muted ? `Unmute ${label}` : `Mute ${label}`}
|
||||||
title={muted ? 'Unmute (M)' : 'Mute (M)'}
|
title={muted ? 'Unmute (M)' : 'Mute (M)'}
|
||||||
disabled={disabled}
|
{disabled}
|
||||||
onclick={onToggleMute}
|
onclick={onToggleMute}
|
||||||
>
|
>
|
||||||
{#if muted}<VolumeX class="media-player-icon" />{:else}<Volume2 class="media-player-icon" />{/if}
|
{#if muted}<VolumeX class="media-player-icon" />{:else}<Volume2 class="media-player-icon" />{/if}
|
||||||
@@ -166,7 +154,7 @@
|
|||||||
step="0.05"
|
step="0.05"
|
||||||
value={displayVolume}
|
value={displayVolume}
|
||||||
aria-label="Volume"
|
aria-label="Volume"
|
||||||
disabled={disabled}
|
{disabled}
|
||||||
oninput={handleVolume}
|
oninput={handleVolume}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -176,7 +164,7 @@
|
|||||||
value={selectedQuality}
|
value={selectedQuality}
|
||||||
aria-label="Video quality"
|
aria-label="Video quality"
|
||||||
title="Video quality"
|
title="Video quality"
|
||||||
disabled={disabled}
|
{disabled}
|
||||||
onchange={handleQuality}
|
onchange={handleQuality}
|
||||||
>
|
>
|
||||||
{#each qualityOptions as option (option.value)}
|
{#each qualityOptions as option (option.value)}
|
||||||
@@ -192,9 +180,8 @@
|
|||||||
aria-label={graphVisible ? 'Hide funscript graph' : 'Show funscript graph'}
|
aria-label={graphVisible ? 'Hide funscript graph' : 'Show funscript graph'}
|
||||||
aria-pressed={graphVisible}
|
aria-pressed={graphVisible}
|
||||||
title={graphVisible ? 'Hide funscript graph' : 'Show funscript graph'}
|
title={graphVisible ? 'Hide funscript graph' : 'Show funscript graph'}
|
||||||
disabled={disabled}
|
{disabled}
|
||||||
onclick={onToggleGraph}
|
onclick={onToggleGraph}><Activity class="media-player-icon" /></button
|
||||||
><Activity class="media-player-icon" /></button
|
|
||||||
>
|
>
|
||||||
{/if}
|
{/if}
|
||||||
{#if showFullscreen}
|
{#if showFullscreen}
|
||||||
@@ -203,7 +190,7 @@
|
|||||||
class="media-player-control"
|
class="media-player-control"
|
||||||
aria-label={fullscreen ? 'Exit fullscreen' : 'Enter fullscreen'}
|
aria-label={fullscreen ? 'Exit fullscreen' : 'Enter fullscreen'}
|
||||||
title={fullscreen ? 'Exit fullscreen (F)' : 'Enter fullscreen (F)'}
|
title={fullscreen ? 'Exit fullscreen (F)' : 'Enter fullscreen (F)'}
|
||||||
disabled={disabled}
|
{disabled}
|
||||||
onclick={() => void onToggleFullscreen?.()}
|
onclick={() => void onToggleFullscreen?.()}
|
||||||
>
|
>
|
||||||
{#if fullscreen}<Minimize2 class="media-player-icon" />{:else}<Maximize2 class="media-player-icon" />{/if}
|
{#if fullscreen}<Minimize2 class="media-player-icon" />{:else}<Maximize2 class="media-player-icon" />{/if}
|
||||||
|
|||||||
Reference in new issue
Block a user