forked from Mastodon/mastoradio-la-radio-di-mastodon
better player bindings
This commit is contained in:
parent
10c7fdba5f
commit
c39314abca
src/components
@ -7,6 +7,7 @@
|
|||||||
class="playerBig__iframe"
|
class="playerBig__iframe"
|
||||||
paused={$paused}
|
paused={$paused}
|
||||||
volume={$volume}
|
volume={$volume}
|
||||||
|
on:loadstart={onLoadStart}
|
||||||
on:canplay={onCanPlay}
|
on:canplay={onCanPlay}
|
||||||
on:play={onPlay}
|
on:play={onPlay}
|
||||||
on:pause={onPause}
|
on:pause={onPause}
|
||||||
@ -113,20 +114,24 @@
|
|||||||
const loading = getContext('loading')
|
const loading = getContext('loading')
|
||||||
const selectNext = getContext('selectNext')
|
const selectNext = getContext('selectNext')
|
||||||
|
|
||||||
let ready = null
|
let ready = false
|
||||||
let currentTime = null
|
let currentTime = null
|
||||||
let duration = null
|
let duration = null
|
||||||
|
|
||||||
|
const onLoadStart = () => {
|
||||||
|
ready = false
|
||||||
|
}
|
||||||
|
|
||||||
const onCanPlay = () => {
|
const onCanPlay = () => {
|
||||||
ready = true
|
ready = true
|
||||||
}
|
}
|
||||||
|
|
||||||
const onPlay = () => {
|
const onPlay = () => {
|
||||||
// $paused = false
|
$paused = false
|
||||||
}
|
}
|
||||||
|
|
||||||
const onPause = () => {
|
const onPause = () => {
|
||||||
// $paused = true
|
$paused = true
|
||||||
}
|
}
|
||||||
|
|
||||||
const onTimeUpdate = event => {
|
const onTimeUpdate = event => {
|
||||||
|
@ -5,18 +5,19 @@
|
|||||||
import { loadIframeApi, STATE } from '/services/youtube.js'
|
import { loadIframeApi, STATE } from '/services/youtube.js'
|
||||||
import { queue } from '/services/misc.js'
|
import { queue } from '/services/misc.js'
|
||||||
|
|
||||||
let element
|
|
||||||
let player
|
|
||||||
let animationFrameId
|
|
||||||
|
|
||||||
let currentTime
|
|
||||||
let duration
|
|
||||||
|
|
||||||
// input props
|
// input props
|
||||||
export let id
|
export let id
|
||||||
export let paused
|
export let paused
|
||||||
export let volume
|
export let volume
|
||||||
|
|
||||||
|
let element
|
||||||
|
let player
|
||||||
|
let animationFrameId
|
||||||
|
|
||||||
|
let loaded = false
|
||||||
|
let currentTime = null
|
||||||
|
let duration = null
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
$: load(id)
|
$: load(id)
|
||||||
@ -28,9 +29,12 @@
|
|||||||
const { enqueue, run } = queue()
|
const { enqueue, run } = queue()
|
||||||
|
|
||||||
export const load = (id) => enqueue((player) => {
|
export const load = (id) => enqueue((player) => {
|
||||||
|
loaded = false
|
||||||
currentTime = null
|
currentTime = null
|
||||||
duration = null
|
duration = null
|
||||||
|
|
||||||
|
dispatch('loadstart')
|
||||||
|
|
||||||
player.cueVideoById(id)
|
player.cueVideoById(id)
|
||||||
|
|
||||||
if (!paused) {
|
if (!paused) {
|
||||||
@ -77,23 +81,30 @@
|
|||||||
break
|
break
|
||||||
|
|
||||||
case STATE.PLAYING:
|
case STATE.PLAYING:
|
||||||
dispatch('play')
|
|
||||||
|
|
||||||
const newDuration = player.getDuration()
|
const newDuration = player.getDuration()
|
||||||
|
|
||||||
if (duration !== newDuration) {
|
if (duration !== newDuration) {
|
||||||
duration = newDuration
|
duration = newDuration
|
||||||
dispatch('durationchange', duration)
|
}
|
||||||
|
|
||||||
|
if (loaded) {
|
||||||
|
dispatch('play')
|
||||||
}
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
case STATE.PAUSED:
|
case STATE.PAUSED:
|
||||||
|
if (loaded) {
|
||||||
dispatch('pause')
|
dispatch('pause')
|
||||||
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
case STATE.CUED:
|
case STATE.CUED:
|
||||||
|
if (!loaded) {
|
||||||
|
loaded = true
|
||||||
|
}
|
||||||
|
|
||||||
dispatch('canplay')
|
dispatch('canplay')
|
||||||
|
|
||||||
break
|
break
|
||||||
|
Loading…
x
Reference in New Issue
Block a user