mastoradio/src/components/Viewer.svelte

71 lines
1.6 KiB
Svelte
Raw Normal View History

2020-01-10 03:02:46 +01:00
<div>
2020-01-18 17:42:44 +01:00
<div class="embed-container" class:hidden={!ready}>
2020-01-18 17:57:02 +01:00
<YoutubePlayer
id={$current ? $current.data.id : null}
paused={$paused}
muted={$muted}
volume={$volume}
bind:ready
bind:ended
bind:currentTime
bind:duration
bind:seek={seek}
></YoutubePlayer>
2020-01-16 20:10:40 +01:00
<div class="embed-overlay" on:click={() => $paused = !$paused}></div>
2020-01-10 15:16:48 +01:00
</div>
2020-01-18 17:42:44 +01:00
{#if !ready}
2020-01-18 05:05:37 +01:00
LOADING TRACK
{/if}
2020-01-10 15:16:48 +01:00
{#if duration}
2020-01-13 14:39:00 +01:00
{currentTimeText}
2020-01-16 20:10:40 +01:00
<input
type="range"
min="0"
max={duration}
value={currentTime}
2020-01-18 17:42:44 +01:00
on:input={(e) => seek(e.target.value, false)}
on:change={(e) => seek(e.target.value, true)}>
2020-01-13 14:39:00 +01:00
{durationText}
2020-01-10 15:16:48 +01:00
{/if}
2020-01-10 03:02:46 +01:00
</div>
<script>
import { get } from 'svelte/store'
2020-01-18 17:42:44 +01:00
import YoutubePlayer from '/components/YoutubePlayer'
2020-01-13 14:39:00 +01:00
import { secondsToElapsedTime } from '/util.js'
2020-01-16 20:10:40 +01:00
import { paused, muted, volume, current, selectNext, loading } from '/store.js'
2020-01-10 03:02:46 +01:00
2020-01-18 17:42:44 +01:00
let ready = null
let ended = null
2020-01-10 15:16:48 +01:00
let currentTime = null
let duration = null
2020-01-18 17:42:44 +01:00
let seek = null
2020-01-13 14:39:00 +01:00
$: currentTimeText = currentTime !== null ? secondsToElapsedTime(currentTime) : null
$: durationText = duration !== null ? secondsToElapsedTime(duration) : null
2020-01-18 17:42:44 +01:00
$: if (ended) {
selectNext()
2020-01-10 03:42:02 +01:00
}
2020-01-10 03:02:46 +01:00
</script>
<style>
2020-01-13 14:39:00 +01:00
.hidden {
display: none;
}
2020-01-16 20:10:40 +01:00
.embed-container {
position: relative;
}
.embed-overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
2020-01-10 03:02:46 +01:00
</style>