jukebox
All repositories: gitoria
3.3 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)`: the context says which list the song was tapped in (`{ kind, sort, minPlays, ... }`,// lib/rows.hl), the index which row. The shell asks the server for the songs of that list from there on (`jbQueue`) and hands them to the media// player as its queue; when a song ends the player picks the next one, and the shell refills the queue before it runs out. The media player's own queue list is hidden by// the bar's CSS (a 13,000-song list is not drawn).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 { rowsFor, queueFor } from '../lib/rows.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 fromString nowSrc = ''String nowTitle = ''String nowArtist = ''String nowCover = ''String nowId = ''String autoPlay = 'false'Hybrid nowQueue = []Hybrid nowCtx = {}String barClass = 'jb-app'View {body {AppHeader { brand = "Jukebox"MainMenu { items = menu }}Sidebar { desktop = "false" MainMenu { items = menu } }div { class = barClassslotdiv { class = "jb-bar"MediaPlayer { src = nowSrc kind = "audio" title = nowTitle artist = nowArtist cover = nowCover queue = nowQueue onPlay = pickedNext autoPlay = autoPlay }}}}}// ---- 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) {return queueFor(ctx, index, count)}// ---- playing -----------------------------------------------------------------------------------------------------------------// show what plays (a queue item) and start itshowNow = (item) => {nowSrc = item.srcnowTitle = item.titlenowArtist = item.artistnowCover = item.covernowId = item.idautoPlay = 'true'barClass = 'jb-app playing'}// a song was tapped in a screen: its list becomes the queueon jbPlay(ctx, index) {items = emit server jbQueue(ctx, index, 40)if (items == null || items.length == 0) { return null }nowCtx = ctxnowQueue = itemsshowNow(items[0])return null}// the player picked a queue item (a tap on it, or the end of the song before): refill the queue when it runs shortpickedNext = (src) => {let at = -1let i = 0while (i < nowQueue.length) {if (nowQueue[i].src == src) { at = i }i = i + 1}if (at < 0) { return }item = nowQueue[at]showNow(item)if (nowQueue.length - at < 10) {more = emit server jbQueue(nowCtx, item.idx, 40)if (more != null && more.length > 0) { nowQueue = more }}}
Branches
Latest commits
- 59c1373ejukebox JB3 (work in progress): albums without folder and with disc markers folded, compilations, duplicate songs, own play counter, server-side shuffle queuemre
- 2a4cfc55jukebox: library screens (songs, artists, albums, artist, album, search, favourites), compact player bar, /stream with Range, thumbnails, virtual list vendored, ui gate and real-library checkmre
- 93a44212jukebox: report, numbers of the full scan, notes on the index key rulemre
- bf5167dajukebox: index keys without commas (mpackdb loses them after a reopen), comma fixture and gate checksmre
- 28a82fa2jukebox: README, STATUS, LOG, DECISIONSmre
- d13987dfjukebox: library scanner, ID3 reader, mpackdb database and JSON API, with fixtures and a gatemre