working on Controls
This commit is contained in:
parent
b9bd642cbf
commit
46ef6f9056
2 changed files with 39 additions and 13 deletions
|
|
@ -208,7 +208,7 @@
|
||||||
{#if possibleToPlayPause}
|
{#if possibleToPlayPause}
|
||||||
{#if showControls}
|
{#if showControls}
|
||||||
<Controls
|
<Controls
|
||||||
on:pausePlayEvent={pausePlayEvent}
|
{pausePlayEvent}
|
||||||
{paused}
|
{paused}
|
||||||
{clickedOnPauseBtn}
|
{clickedOnPauseBtn}
|
||||||
controlsOpacity={hoverToSeeControls ?
|
controlsOpacity={hoverToSeeControls ?
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,38 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Fa from 'svelte-fa';
|
import Fa from 'svelte-fa';
|
||||||
import { faReply, faPlay, faPause } from '@fortawesome/free-solid-svg-icons';
|
import { faReply, faPlay, faPause } from '@fortawesome/free-solid-svg-icons';
|
||||||
import { createEventDispatcher } from 'svelte';
|
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
interface Props {
|
||||||
|
/** Function that controls pause/play event */
|
||||||
|
pausePlayEvent: (e: CustomEvent) => void;
|
||||||
|
/** Boolean, paused or playing */
|
||||||
|
paused: boolean;
|
||||||
|
/** Boolean, clicked on pause button */
|
||||||
|
clickedOnPauseBtn: boolean;
|
||||||
|
/** Change the opacity of the play/pause button */
|
||||||
|
controlsOpacity?: number;
|
||||||
|
/** Have four options for controls position - top right, top left, bottom right, bottom left */
|
||||||
|
controlsPosition?:
|
||||||
|
| 'top right'
|
||||||
|
| 'top left'
|
||||||
|
| 'bottom right'
|
||||||
|
| 'bottom left';
|
||||||
|
/** Width of the video container */
|
||||||
|
widthVideoContainer: number;
|
||||||
|
/** Height of the video container */
|
||||||
|
heightVideoContainer: number;
|
||||||
|
/** Colour of the controls */
|
||||||
|
controlsBorderOffset: number;
|
||||||
|
/** Whether to use a separate replay icon or use the play icon for replay as well */
|
||||||
|
separateReplayIcon?: boolean;
|
||||||
|
/** Change the colour of the play/pause button */
|
||||||
|
controlsColour?: string;
|
||||||
|
/** Whether to reset condition */
|
||||||
|
resetCondition: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
let {
|
let {
|
||||||
|
pausePlayEvent,
|
||||||
paused = $bindable(),
|
paused = $bindable(),
|
||||||
clickedOnPauseBtn = $bindable(),
|
clickedOnPauseBtn = $bindable(),
|
||||||
controlsOpacity,
|
controlsOpacity,
|
||||||
|
|
@ -16,20 +43,19 @@
|
||||||
resetCondition,
|
resetCondition,
|
||||||
separateReplayIcon,
|
separateReplayIcon,
|
||||||
controlsColour,
|
controlsColour,
|
||||||
} = $props();
|
}: Props = $props();
|
||||||
|
|
||||||
function forwardBtnClick() {
|
function forwardBtnClick() {
|
||||||
paused = !paused;
|
paused = !paused;
|
||||||
clickedOnPauseBtn = paused === true; // so video doesn't autoplay when coming into view again if paused previously
|
clickedOnPauseBtn = paused === true; // so video doesn't autoplay when coming into view again if paused previously
|
||||||
dispatch('pausePlayEvent', {
|
|
||||||
paused,
|
|
||||||
clickedOnPauseBtn,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
onclick="{forwardBtnClick}"
|
onclick={() => {
|
||||||
|
forwardBtnClick();
|
||||||
|
pausePlayEvent();
|
||||||
|
}}
|
||||||
style="
|
style="
|
||||||
opacity: {controlsOpacity};
|
opacity: {controlsOpacity};
|
||||||
top: {controlsPosition === 'top left' || controlsPosition === 'top right' ?
|
top: {controlsPosition === 'top left' || controlsPosition === 'top right' ?
|
||||||
|
|
@ -50,18 +76,18 @@
|
||||||
{#if resetCondition}
|
{#if resetCondition}
|
||||||
<i class="play-pause-icon replay">
|
<i class="play-pause-icon replay">
|
||||||
{#if separateReplayIcon}
|
{#if separateReplayIcon}
|
||||||
<Fa icon="{faReply}" size="2x" color="{controlsColour}" />
|
<Fa icon={faReply} size="2x" color={controlsColour} />
|
||||||
{:else}
|
{:else}
|
||||||
<Fa icon="{faPlay}" size="2x" color="{controlsColour}" />
|
<Fa icon={faPlay} size="2x" color={controlsColour} />
|
||||||
{/if}
|
{/if}
|
||||||
</i>
|
</i>
|
||||||
{:else if paused === false}
|
{:else if paused === false}
|
||||||
<i class="play-pause-icon pause">
|
<i class="play-pause-icon pause">
|
||||||
<Fa icon="{faPause}" size="2x" color="{controlsColour}" />
|
<Fa icon={faPause} size="2x" color={controlsColour} />
|
||||||
</i>
|
</i>
|
||||||
{:else if paused === true}
|
{:else if paused === true}
|
||||||
<i class="play-pause-icon play">
|
<i class="play-pause-icon play">
|
||||||
<Fa icon="{faPlay}" size="2x" color="{controlsColour}" />
|
<Fa icon={faPlay} size="2x" color={controlsColour} />
|
||||||
</i>
|
</i>
|
||||||
{:else}
|
{:else}
|
||||||
error
|
error
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue