mastoradio-la-radio-di-mast.../src/components/Viewer.svelte

61 lines
1.7 KiB
Svelte
Raw Normal View History

2020-02-15 23:10:03 +01:00
<div class="playerBig">
2020-02-15 20:13:33 +01:00
<div class="playerBig__player">
2020-01-18 17:57:02 +01:00
<YoutubePlayer
id={$current ? $current.data.id : null}
2020-02-15 20:13:33 +01:00
class="playerBig__iframe"
2020-01-18 17:57:02 +01:00
paused={$paused}
muted={$muted}
volume={$volume}
bind:ready
bind:ended
2020-01-18 18:21:07 +01:00
bind:error
2020-01-18 17:57:02 +01:00
bind:currentTime
bind:duration
bind:seek={seek}
></YoutubePlayer>
2020-02-15 20:13:33 +01:00
<div class="playerBig__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-02-15 23:10:03 +01:00
<Progress
duration={duration}
currentTime={currentTime}
currentTimeText={currentTimeText}
durationText={durationText}
on:input={event => updateCurrentTime(event.target.value, false)}
on:change={event => updateCurrentTime(event.target.value, true)}
></Progress>
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-02-15 23:10:03 +01:00
import Progress from '/components/player/Progress'
2020-01-20 03:26:18 +01:00
import { secondsToElapsedTime } from '/services/misc.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-02-15 23:10:03 +01:00
2020-01-18 17:42:44 +01:00
let ready = null
let ended = null
2020-01-18 18:21:07 +01:00
let error = 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
2020-02-14 16:48:49 +01:00
$: currentTimeText = currentTime !== null ? secondsToElapsedTime(currentTime) : '--:--'
$: durationText = duration !== null ? secondsToElapsedTime(duration) : '--:--'
2020-01-13 14:39:00 +01:00
2020-01-18 18:21:07 +01:00
$: if (ended || error) {
2020-01-18 17:42:44 +01:00
selectNext()
2020-01-10 03:42:02 +01:00
}
2020-01-20 03:26:18 +01:00
const updateCurrentTime = (seconds, seekAhead) => {
seek(seconds, seekAhead)
currentTime = seconds
}
2020-01-10 03:02:46 +01:00
</script>