jukebox
All repositories: gitoria
27.5 KB
// components/main.hl — THE SHELL: the layouts header with the main menu (the phone's sidebar behind the toggle), the slot every screen renders// into, and the PLAYER BAR at the bottom. The shell stays when a screen is replaced by a click on a link (hl:web navigates in the page), so the song keeps playing// while you browse. A screen starts a song with `emit jbPlay(ctx, index, id)`: the context says which list the song was tapped in (`{ kind, sort, minPlays, ... }`,// lib/rows.hl), the id WHICH SONG (the id decides, the server looks the song up in the list as it is now; the index is only where the screen saw it, counted plays move songs). A screen starts a shuffle with `emit jbShuffle(spec)` (lib/queue.hl: favourites or the list the screen shows); the server then holds the// shuffled order and the browser asks for 40 songs at a time. The queue of the media player always starts at the song that plays: the bar shows it, the overlay lists the 20 after it.// THE NOW-PLAYING OVERLAY is the same bar and the same media player, drawn bigger by CSS: a tap on the bar opens it (full screen on the phone, a side panel from 60rem), the// close button, the Escape key or a swipe down closes it. THE COUNT: a song counts as played after half of its length or 4 minutes of listening (whichever comes first); the shell counts// the seconds the audio really plays (a one second timer), asks the server once (`jbPlayed`) and the jukebox database adds 1 to its own counter. The files are never written.// KEYBOARD: NOT HERE. Every key handler of the shell (document listener, body, the app div) made the audio element load its source again on each key press (the song// restarted): Hybriel gap, repro in reports/JB3b-keyboard-gap.md. The media player's own keys (Space, arrows on its audio element) stay as they are.// THE BAR'S BUTTONS, left to right: Shuffle, Previous, Play / pause, Next, Repeat (no 10 second jumps). Shuffle is a switch: on = the songs still to come are shuffled from the song that plays// (the shuffle context below, seeded), off = the list's own order goes on after it; the song that plays is kept. Repeat steps off, all, one: one = the media player's own loop,// all = at the end of the queue the list starts again from its first song, off = it stops. Both are kept in storage/ui.json (lib/remember.hl).// LOCK SCREEN: the browser's media session shows title, artist, album and cover and gives play, pause, previous and next to the lock screen and the headphone keys.import AppHeader from '../theme/shell/app-header.hl'import MainMenu from '../theme/shell/main-menu.hl'import Sidebar from '../theme/shell/app-sidebar.hl'import MediaPlayer from './media-player/media-player.hl'import Icon from './icons/icons.hl'import { now } from 'hl:time'import { rowsFor, queueFor } from '../lib/rows.hl'import { countPlay } from '../lib/plays.hl'import { showOf } from '../lib/dups.hl'import { lastShuffle, lastRepeat, rememberPlayer } from '../lib/remember.hl'slot = nullmenu = [ { label = 'Songs' href = '/' current = false } { label = 'Artists' href = '/artists' } { label = 'Albums' href = '/albums' } { label = 'Search' href = '/search' } ]// the player: what plays now, and the songs that follow in the list it came from (the first item of the queue is the song that plays)String nowSrc = ''String nowTitle = ''String nowArtist = ''String nowAlbum = ''String nowCover = ''String nowArt = ''String nowId = ''String autoPlay = 'false'Hybrid nowQueue = []Hybrid nowCtx = {}Number nowIdx = 0String overlay = 'false'String barClass = 'jb-app'String coverNow = overlay == 'true' ? nowArt : nowCoverNumber heard = 0String countedId = ''Number swipeY = -1String ticking = 'false'String shuffleMode = lastShuffle()String repeatMode = lastRepeat()Boolean shuffleOn = shuffleMode == 'on'Boolean repeatOn = repeatMode != 'off'String repeatValue = repeatMode == 'one' ? 'one' : 'off'String repeatIcon = repeatMode == 'one' ? 'repeatOne' : 'repeat'String shuffleTitle = 'Shuffle: ' + shuffleModeString repeatTitle = 'Repeat: ' + (repeatMode == 'off' ? 'off' : repeatMode == 'all' ? 'all songs' : 'this song')Style {// Keep the quoted class selector and its original specificity.'.jb-app' { '--jb-bar' = '0rem' }// Keyframes use the documented quoted animation key.'@keyframes jb-mount' {'from' { opacity = '.999' }to { opacity = '1' }}jbTick {display = 'block'height = '0'animation = 'jb-mount 100ms linear infinite'}// Caller page supplies jb-screen through the slot; retain its exact tag selector.'jb-screen' {display = 'flex'flexDirection = 'column'height = 'calc(100dvh - var(--layout-header) - var(--jb-bar))'paddingInline = 'max(var(--layout-gutter), calc((100% - var(--layout-column)) / 2))'paddingTop = '.5rem'// Keep the quoted child selector into the composed virtual list.'> virtual-list' {flex = '1 1 auto'height = 'auto'minHeight = '0'marginInline = '-.6rem'}@media {minWidth = '60rem'paddingTop = '1rem'}}// Keep the quoted class selector and its original specificity.'.jb-bar' {display = 'none'mediaPlayer {display = 'contents'// Keep the quoted selector into the composed media player.'.mp-cover' {gridArea = 'cover'display = 'flex'alignItems = 'center'gap = '.6rem'margin = '0'minWidth = '0'paddingInline = 'max(var(--layout-gutter), calc((100% - var(--layout-column)) / 2))'cursor = 'pointer'div { minWidth = '0' }p {margin = '0'fontSize = '.8rem'overflow = 'hidden'textOverflow = 'ellipsis'whiteSpace = 'nowrap'}img {width = '2.5rem'height = '2.5rem'}h2 {margin = '0'fontSize = '.95rem'lineHeight = '1.3'fontWeight = '600'overflow = 'hidden'textOverflow = 'ellipsis'whiteSpace = 'nowrap'}}mpButtons {display = 'contents'// Keep the quoted selector into the composed media player.'.mp-play' {gridArea = 'buttons'background = 'transparent'}// Keep the quoted selector into the composed media player.'.mp-mute' { display = 'none' }// Keep the quoted selector into the composed media player.'.mp-speed' { display = 'none' }// Keep the quoted selector into the composed media player.'.mp-times' { display = 'none' }}mpSeek { gridArea = 'seek' }audio { display = 'none' }}// Keep the quoted class selector and its original specificity.'.jb-close' {display = 'none'hover { background = 'var(--color-surface)' }}// Keep the quoted class selector and its original specificity.'.jb-album' { display = 'none' }// Keep the quoted class selector and its original specificity.'button.jb-prev' {display = 'inline-flex'alignItems = 'center'justifyContent = 'center'minWidth = '2.75rem'minHeight = '2.75rem'margin = '0'padding = '0'color = 'var(--color-text)'background = 'transparent'borderRadius = 'var(--radius-small)'gridArea = 'prev'hover { background = 'var(--color-surface)' }}// Keep the quoted class selector and its original specificity.'button.jb-next' {display = 'inline-flex'alignItems = 'center'justifyContent = 'center'minWidth = '2.75rem'minHeight = '2.75rem'margin = '0'padding = '0'color = 'var(--color-text)'background = 'transparent'borderRadius = 'var(--radius-small)'gridArea = 'next'hover { background = 'var(--color-surface)' }}// Shuffle, before Previous: a switch, the accent colour and a surface behind it when on.#jbShuffle {display = 'inline-flex'alignItems = 'center'justifyContent = 'center'minWidth = '2.75rem'minHeight = '2.75rem'margin = '0'padding = '0'color = 'var(--color-text)'background = 'transparent'borderRadius = 'var(--radius-small)'gridArea = 'shuffle'hover { background = 'var(--color-surface)' }}// Repeat, after Next: off / all / one; the accent colour and a surface behind it when not off.#jbRepeat {display = 'inline-flex'alignItems = 'center'justifyContent = 'center'minWidth = '2.75rem'minHeight = '2.75rem'margin = '0'padding = '0'color = 'var(--color-text)'background = 'transparent'borderRadius = 'var(--radius-small)'gridArea = 'repeat'marginRight = 'max(.25rem, calc((100vw - var(--layout-column)) / 2))'hover { background = 'var(--color-surface)' }}}// Keep the quoted class selector and its original specificity.'.jb-app.playing' {'--jb-bar' = '4.625rem'// Keep the quoted class selector and its original specificity.'.jb-bar' {display = 'grid'position = 'fixed'left = '0'right = '0'bottom = '0'zIndex = '15'height = 'var(--jb-bar)'background = 'var(--color-background-sunken)'gridTemplateColumns = 'minmax(0, 1fr) auto auto auto auto auto'gridTemplateRows = '1.375rem 1fr'gridTemplateAreas = '"seek seek seek seek seek seek" "cover shuffle prev buttons next repeat"'alignItems = 'center'}@media {minWidth = '60rem''--jb-bar' = '5.125rem'}}// Shuffle and Repeat when on: a nested quoted compound would be a descendant, so the state rule is whole (id and attribute on the same button).// The framework writes an id kebab-case (hybriel#256) in nested rules but not inside a quoted key: here the id is written as it is sent.'.jb-bar #jb-shuffle[aria-pressed="true"], .jb-bar #jb-repeat[aria-pressed="true"]' {color = 'var(--color-accent)'background = 'var(--color-surface)'}// Keep the quoted condition: :not() has no bare form.'.jb-app:not(.open)' {// Keep the quoted class selector and its original specificity.'.jb-bar' {mediaPlayer {mpSeek {height = '1.375rem'margin = '0'// Keep the quoted selector into the composed media player.'.mp-track' {top = '0'left = '0'right = '0'height = '1.375rem'borderRadius = '0'}// Keep the quoted selector into the composed media player.'.mp-thumb' { display = 'none' }}// Keep the quoted condition: :not() has no bare form.'> div:not(.mp-cover)' { display = 'none' }mpButtons {// Keep the quoted selector into the composed media player.'.mp-times' {@media {minWidth = '60rem'display = 'inline-flex'marginLeft = '.5rem'}}}}}}// Keep the quoted class selector and its original specificity.'.jb-app.open' {'--jb-bar' = '0rem'// Keep the quoted class selector and its original specificity.'.jb-bar' {display = 'grid'position = 'fixed'top = '0'left = '0'right = '0'bottom = '0'zIndex = '40'height = 'auto'background = 'var(--color-background)'gridTemplateColumns = '1fr 3rem 3rem 3.5rem 3rem 3rem 1fr'gridTemplateRows = 'auto auto auto auto auto auto minmax(0, 1fr)'gridTemplateAreas = 'none'alignItems = 'center'justifyItems = 'center'touchAction = 'none'paddingBottom = 'env(safe-area-inset-bottom)'// Keep the quoted class selector and its original specificity.'.jb-close' {display = 'inline-flex'gridColumn = '1 / -1'gridRow = '1'justifySelf = 'end'alignItems = 'center'justifyContent = 'center'minWidth = '2.75rem'minHeight = '2.75rem'margin = '.25rem .5rem 0'padding = '0'color = 'var(--color-text)'background = 'transparent'borderRadius = 'var(--radius-small)'}mediaPlayer {// Keep the quoted selector into the composed media player.'.mp-cover' {gridArea = 'auto'gridColumn = '1 / -1'gridRow = '2'flexDirection = 'column'gap = '.6rem'width = '100%'paddingInline = '1.5rem'cursor = 'default'textAlign = 'center'p {fontSize = '1rem'whiteSpace = 'normal'textAlign = 'center'}img {width = 'clamp(0px, calc(100dvh - 36rem), min(calc(100vw - 3rem), 32dvh))'height = 'clamp(0px, calc(100dvh - 36rem), min(calc(100vw - 3rem), 32dvh))'maxWidth = '100%'@media {maxHeight = '41rem'display = 'none'}@media {minWidth = '60rem'width = 'clamp(0px, calc(100dvh - 36rem), min(18rem, 32dvh))'height = 'clamp(0px, calc(100dvh - 36rem), min(18rem, 32dvh))'}}h2 {fontSize = '1.25rem'overflow = 'visible'whiteSpace = 'normal'textAlign = 'center'}}mpSeek {gridArea = 'auto'gridColumn = '1 / -1'gridRow = '4'justifySelf = 'stretch'height = '1.375rem'marginInline = '1.25rem'// Keep the quoted selector into the composed media player.'.mp-track' {top = '0'height = '1.375rem'}// Keep the quoted selector into the composed media player.'.mp-thumb' { display = 'none' }}mpButtons {// Keep the quoted selector into the composed media player.'.mp-play' {gridArea = 'auto'gridColumn = '4'gridRow = '5'background = 'var(--color-surface)'}// Keep the quoted selector into the composed media player.'.mp-times' {display = 'inline-flex'gridColumn = '2 / 5'gridRow = '6'justifySelf = 'start'marginLeft = '0'}// Keep the quoted selector into the composed media player.'.mp-mute' {display = 'inline-flex'gridColumn = '5'gridRow = '6'}// Keep the quoted selector into the composed media player.'.mp-speed' {display = 'inline-flex'gridColumn = '6'gridRow = '6'}}// Keep the quoted condition: :not() has no bare form.'> div:not(.mp-cover)' {display = 'block'gridColumn = '1 / -1'gridRow = '7'justifySelf = 'stretch'alignSelf = 'stretch'minHeight = '0'overflowY = 'auto'padding = '0 .75rem .75rem'touchAction = 'pan-y'}// Keep the quoted selector into the composed media player.'.mp-queue-title' {margin = '.5rem .25rem .1rem'fontSize = '.85rem'letterSpacing = '.04em'textTransform = 'uppercase'color = 'var(--color-text-muted)'}// Keep the quoted selector into the composed media player.'ol.mp-queue' {// One column the width of the panel: a long title in the queue must not widen the grid past the screen (the times went off to the right).gridTemplateColumns = 'minmax(0, 1fr)'// Keep the quoted functional pseudo-class.'li:nth-child(n+22)' { display = 'none' }// Keep the quoted selector into the composed media player.'.mp-q-title' {overflow = 'hidden'textOverflow = 'ellipsis'whiteSpace = 'nowrap'overflowWrap = 'normal'}}}// Keep the quoted class selector and its original specificity.'.jb-album' {display = 'block'gridColumn = '1 / -1'gridRow = '3'margin = '.1rem 1.5rem 0'textAlign = 'center'color = 'var(--color-text-muted)'@media {maxHeight = '41rem'display = 'none'}}// Keep the quoted class selector and its original specificity.'button.jb-prev' {gridArea = 'auto'gridColumn = '3'gridRow = '5'}// Keep the quoted class selector and its original specificity.'button.jb-next' {gridArea = 'auto'gridColumn = '5'gridRow = '5'}#jbShuffle {gridArea = 'auto'gridColumn = '2'gridRow = '5'}#jbRepeat {gridArea = 'auto'gridColumn = '6'gridRow = '5'marginRight = '0'}@media {minWidth = '60rem'top = 'var(--layout-header)'left = 'auto'width = '24rem'zIndex = '15'}}@media {minWidth = '60rem''--jb-bar' = '0rem'}// Caller page supplies jb-screen through the slot; retain its exact tag selector.'jb-screen' {@media {minWidth = '60rem'marginRight = '24rem'}}}}View {body {AppHeader { brand = "Jukebox"MainMenu { items = menu }}Sidebar { desktop = "false" MainMenu { items = menu } }div { class = barClassslotjbTick { on animationiteration(e) { emit jbMount(e) } }div { class = "jb-bar" on click(e) { emit jbBarClick(e) } on pointerdown(e) { emit jbDown(e) } on pointerup(e) { emit jbUp(e) } on pointercancel(e) { emit jbCancel(e) }button { type = "button" class = "jb-close" title = "Close" 'aria-label' = "Close" Icon { name = "close" size = "1.5em" } on click(e) { emit jbClose(e) } }MediaPlayer { queueLabel = "Next up" src = nowSrc kind = "audio" title = nowTitle artist = nowArtist cover = coverNow queue = nowQueue onPlay = pickedNext autoPlay = autoPlay skip = false repeat = repeatValue }p { class = "jb-album" nowAlbum }button { id = "jbShuffle" type = "button" title = shuffleTitle 'aria-label' = "Shuffle" 'aria-pressed' = shuffleOn Icon { name = "shuffle" size = "1.5em" } on click(e) { emit jbShuffleClick(e) } }button { type = "button" class = "jb-prev" title = "Previous song" 'aria-label' = "Previous song" Icon { name = "prevTrack" size = "1.5em" } on click(e) { emit jbPrevClick(e) } }button { type = "button" class = "jb-next" title = "Next song" 'aria-label' = "Next song" Icon { name = "nextTrack" size = "1.5em" } on click(e) { emit jbNextClick(e) } }button { id = "jbRepeat" type = "button" title = repeatTitle 'aria-label' = "Repeat" 'aria-pressed' = repeatOn Icon { name = repeatIcon size = "1.5em" } on click(e) { emit jbRepeatClick(e) } }}}}}// ---- the server's part -------------------------------------------------------------------------------------------------------// rows of a list for a screen: `{ total, offset, rows }`on server jbRows(ctx, offset, limit) {return rowsFor(ctx, offset, limit)}// the songs of a list from `index` on, as queue itemson server jbQueue(ctx, index, count, id, step, again) {return queueFor(ctx, index, count, id, step, again)}// a new shuffle of a pool (`{ kind: 'favourites', minPlays }` or `{ kind: 'list', ctx }`): its context, with a seed from the clock.// `first` is the id of a song that must come first (a shuffle turned on while it plays), or nullon server jbShuffleCtx(spec, first) {return { kind = 'shuffle' seed = now() % 2147483000 spec = spec first = first }}// Shuffle and Repeat were changed: kept for the next visiton server jbRemember(shuffle, repeat) {return rememberPlayer(shuffle, repeat)}// the song was listened to long enough: the jukebox database adds 1 to its own counter (the same call as POST /api/played/<id>).// The open screen is told the new count and writes that row itself.on server jbPlayed(id) {c = countPlay(id, now())if (c != null) { emit client jbPlays(c.id, showOf(c.id, c.filePlays).plays) }return c}// ---- playing -----------------------------------------------------------------------------------------------------------------setBar = () => {barClass = 'jb-app' + (nowId != '' ? ' playing' : '') + (overlay == 'true' ? ' open' : '')}// the audio element of the media playeraudioEl = () => { return document.querySelector('media-player audio') }// show what plays (a queue item) and start itshowNow = (item) => {nowSrc = item.srcnowTitle = item.titlenowArtist = item.artistnowAlbum = item.albumnowCover = item.covernowArt = item.artnowId = item.idnowIdx = item.idxheard = 0countedId = ''autoPlay = 'true'setBar()let ms = window.navigator.mediaSessionif (ms != null) {ms.metadata = window.Reflect.construct(window.MediaMetadata, [ { title = item.title artist = item.artist album = item.album artwork = [ { src = item.art } ] } ])}}// a queue that starts at the song that playsfromPlace = (at) => {out = []let i = atwhile (i < nowQueue.length) {out.push(nowQueue[i])i = i + 1}return out}// the button or row that started a song gives the focus back (the player's own buttons keep it), so Space keeps meaning play / pauseon jbUnfocus() {f = document.activeElementif (f != null && f.blur != null && f.closest('media-player') == null) { f.blur() }return null}// a song was tapped in a screen: its list becomes the queueon jbPlay(ctx, index, id) {emit jbUnfocus()let playCtx = ctxlet at = indexif (shuffleMode == 'on' && ctx.kind != 'shuffle' && id != null && id != '') {playCtx = emit server jbShuffleCtx({ kind = 'list' ctx = ctx }, id)at = 0}items = emit server jbQueue(playCtx, at, 40, id, 0, againNow())if (items == null || items.length == 0) { return null }nowCtx = playCtxnowQueue = itemsshowNow(items[0])return null}// a shuffle was asked for (a Shuffle button of a screen): the Shuffle switch goes on, a new random order of the pool is played from its starton jbShuffle(spec) {emit jbUnfocus()setShuffle('on')ctx = emit server jbShuffleCtx(spec, null)emit jbPlay(ctx, 0)return null}// the place of a song in the queue, -1 when it is not thereplaceOf = (src) => {let at = -1let i = 0while (i < nowQueue.length) {if (nowQueue[i].src == src) { at = i }i = i + 1}return at}// the player picked a queue item (a tap on it, or the end of the song before): it becomes the first of the queue; the queue is refilled when fewer than 25 songs followpickedNext = (src) => {at = placeOf(src)if (at < 0) { return }item = nowQueue[at]sameSrc = nowSrcnowQueue = fromPlace(at)showNow(item)if (item.src == sameSrc) { replayNow() }if (nowQueue.length < 25) {more = emit server jbQueue(nowCtx, item.idx, 40, item.id, 0, againNow())if (more != null && more.length > 0) { nowQueue = more }}}// next song: the second of the queue, or a request when the list has run out of items hereon jbNext() {if (nowId == '') { return null }if (nowQueue.length > 1) { pickedNext(nowQueue[1].src) return null }more = emit server jbQueue(nowCtx, nowIdx + 1, 40, nowId, 1, againNow())if (more != null && more.length > 0) {nowQueue = moreshowNow(more[0])}return null}// previous song: after 3 seconds into a song the first press starts it again, then the song before it in the liston jbPrev() {if (nowId == '') { return null }let a = audioEl()if (a != null && a.currentTime > 3) { a.currentTime = 0 return null }if (nowIdx < 1) { if (a != null) { a.currentTime = 0 } return null }items = emit server jbQueue(nowCtx, nowIdx - 1, 40, nowId, -1, againNow())if (items != null && items.length > 0) {nowQueue = itemsshowNow(items[0])}return null}// the buttons give the focus back, so Space keeps meaning play / pauseon jbNextClick(e) { e.target.closest('button').blur() emit jbNext() return null }on jbPrevClick(e) { e.target.closest('button').blur() emit jbPrev() return null }// ---- Shuffle and Repeat ----------------------------------------------------------------------------------------------------// Repeat all: the queue never ends (asked of the server with every queue request)againNow = () => { return repeatMode == 'all' }// start the song that plays again (the same song follows itself: Repeat all on a list of one song)replayNow = () => {let a = audioEl()if (a == null) { return }a.currentTime = 0a.play()}// both switches are written into the page and kept for the next visitsetShuffle = (mode) => {shuffleMode = modeemit server jbRemember(shuffleMode, repeatMode)}setRepeat = (mode) => {repeatMode = modeemit server jbRemember(shuffleMode, repeatMode)}// the plain list a shuffle was made frombaseOf = (ctx) => {if (ctx.spec.kind == 'favourites') { return { kind = 'songs' sort = 'title' minPlays = ctx.spec.minPlays } }return ctx.spec.ctx}// a new queue from the song that plays on, in the given context: the song itself stays the first (its src does not change, so the audio goes on)requeue = (ctx) => {items = emit server jbQueue(ctx, ctx.kind == 'shuffle' ? 0 : nowIdx, 40, nowId, 0, againNow())if (items == null || items.length == 0 || items[0].id != nowId) { return }nowCtx = ctxnowQueue = itemsnowIdx = items[0].idx}// Shuffle on: what is still to come is shuffled from the song that plays; the song stayson jbShuffleOn() {setShuffle('on')if (nowId != '' && nowCtx.kind != 'shuffle') {ctx = emit server jbShuffleCtx({ kind = 'list' ctx = nowCtx }, nowId)requeue(ctx)}return null}// Shuffle off: the list's own order goes on after the song that plays; the song stayson jbShuffleOff() {setShuffle('off')if (nowId != '' && nowCtx.kind == 'shuffle') { requeue(baseOf(nowCtx)) }return null}on jbShuffleClick(e) {e.target.closest('button').blur()if (shuffleMode == 'on') { emit jbShuffleOff() } else { emit jbShuffleOn() }return null}// Repeat: off, then all, then one, then off againon jbRepeatClick(e) {e.target.closest('button').blur()setRepeat(repeatMode == 'off' ? 'all' : repeatMode == 'all' ? 'one' : 'off')if (nowId != '') { requeue(nowCtx) }return null}// a song ended with nothing after it (Repeat all on a list of one song): it plays again; with more songs queued the media player picks the next one itselfon jbEnded() {if (repeatMode == 'all' && nowQueue.length == 1) { replayNow() }return null}toggleNow = () => {let a = audioEl()if (a == null || nowId == '') { return }if (a.paused) { a.play() } else { a.pause() }}jumpBy = (seconds) => {let a = audioEl()if (a == null || nowId == '') { return }let t = a.currentTime + secondsif (t < 0) { t = 0 }if (a.duration > 0 && t > a.duration) { t = a.duration }a.currentTime = t}// ---- the overlay ---------------------------------------------------------------------------------------------------------------on jbOpen() {if (nowId == '') { return null }overlay = 'true'setBar()return null}on jbClose(e) {if (e.target != null && e.target.closest != null && e.target.closest('button') != null) { e.target.closest('button').blur() }overlay = 'false'setBar()return null}// a tap on the bar (not on a button or the seek line) opens the overlayon jbBarClick(e) {if (overlay == 'true') { return null }if (e.target.closest('button, mp-seek') != null) { return null }emit jbOpen()return null}// a swipe down over the cover or the title closes it (not over the buttons, the seek line or the queue, which scroll)on jbDown(e) {if (overlay != 'true' || e.target.closest('button, mp-seek, ol') != null) { swipeY = -1 return null }swipeY = e.clientYreturn null}on jbUp(e) {if (swipeY >= 0 && e.clientY - swipeY > 80) { overlay = 'false' setBar() }swipeY = -1return null}on jbCancel(e) { swipeY = -1 return null }// ---- counting, keys and the lock screen -----------------------------------------------------------------------------------// every second: the seconds the audio really played; at half the song or 4 minutes the server counts the play, onceon jbTick() {let a = audioEl()if (a == null || nowId == '' || a.paused || a.ended) { return null }heard = heard + 1let need = 240if (a.duration > 0 && a.duration / 2 < 240) { need = a.duration / 2 }if (heard >= need && countedId != nowId) {countedId = nowIdemit server jbPlayed(nowId)}return null}// the mount tick (the media player's trick): once the page is live the timer, the keys and the lock screen's buttons are set upon jbMount(e) {e.target.style.animationName = 'none'if (ticking == 'true') { return null }ticking = 'true'window.setInterval(() => { emit jbTick() }, 1000)document.addEventListener('ended', (ev) => { emit jbEnded() }, true)let ms = window.navigator.mediaSessionif (ms != null) {ms.setActionHandler('play', () => { toggleNow() })ms.setActionHandler('pause', () => { toggleNow() })ms.setActionHandler('previoustrack', () => { emit jbPrev() })ms.setActionHandler('nexttrack', () => { emit jbNext() })}return null}
Branches
Latest commits
- 8ed6da45|||PR README: media-player pin df9e7dfmre
- d5d45fc3|||PR media-player df9e7df (repeat-one fix), sync pin and SOURCEmre
- 89cdabb1Vendor Hybriel day41 (57054d9e): plugin dirs, set .somre
- 1fecd6a7Merge branch 'records-day39' into mainJukebox
- d6b3e068|||PR Records: day39 live (PR #2), mission 011 PR step, statusmre
- 5fa19e89Merge branch 'day39' into mainJukebox
- cfe95440|||PR day39 re-vendor: Hybriel 51e921d7 (bin 6b481aa7), ids kebab-case since hybriel#256: quoted state rule and tests use jb-shuffle / jb-repeatmre
- f3614c9bRe-vendor to Hybriel day39 (51e921d7, bin 6b481aa7)mre
- 9f5c6532Merge branch 'status-22-pr' into mainJukebox
- 5838d6c7|||PR STATUS: #22 pending decision, PR-only rulemre
- 29d2029cRecords: PR-only rule (Kunibert)mre
- adacb0abRecords: neutral ticket rule, #22 decision recordedmre
- b2d6f121Records: #308 hold liftedmre
- 7ab67533Records: day39 on hold (hybriel#308)mre
- 22f21739Records: note rebase before mergemre
- f7368ea3Records: mission 011 day39, waits for lisbethmre
- 9515d2cdRecords: jb20 livemre
- 019f6601ui gate: comment names the open bug components#27 (workaround, not fixed)mre
- 277a2722README: provenance linemre
- 4169ca6aREADME: sync pinmre