gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmain10f8a8c8Merge branch 'code-order' into mainJukeboxmain/components/media-player/media-player.hl

21.2 KB

  1. // media-player.hl — THE MEDIA PLAYER, all Hybriel (no JavaScript file): audio and video in one phone-first player.
  2. // `MediaPlayer { src = "/media/x.mp4" kind = "video" title = "The clip" artist = "Someone" }` — `kind = "audio"` shows a
  3. // cover image (`cover`) with the title and artist instead of the video area. The browser's own media element plays (no
  4. // `controls`: this component draws the controls, sized for a thumb): a seek bar you drag with a finger (the played part in
  5. // the accent colour, the buffered part as a lighter bar, a 44 px tall touch area with a thin visible bar), Back 10 s,
  6. // play/pause (the largest button), Forward 10 s, mute, the current time / total time, the playback speed (1 / 1.25 / 1.5 / 2)
  7. // and, on video, fullscreen. THE QUEUE is the host's list: `queue = [{ src, title, dur }]` renders under the player, the
  8. // item that plays is marked with the accent colour only, and a tap calls the host's function with the record's `src`
  9. // (hybriel#87: a child talks upward through a function its host gives it) — the host hands a new `src` back, the player
  10. // loads and plays it; when an item ends, the next one is picked the same way. USE ONE PER PAGE (a composed component's
  11. // members are the page's state). Keyboard: the media element takes the focus (a click on it), Space plays / pauses,
  12. // ArrowLeft / ArrowRight jump 10 s. The handlers read the elements' own state, never the members.
  13. import Icon from '../icons/icons.hl'
  14. String src = ''
  15. String kind = 'video'
  16. String title = ''
  17. String artist = ''
  18. String cover = ''
  19. String playLabel = 'Play'
  20. String pauseLabel = 'Pause'
  21. String backLabel = 'Back 10 seconds'
  22. String forwardLabel = 'Forward 10 seconds'
  23. String muteLabel = 'Mute'
  24. String unmuteLabel = 'Unmute'
  25. String speedLabel = 'Playback speed'
  26. String fullscreenLabel = 'Fullscreen'
  27. String queueLabel = 'Queue'
  28. Hybrid queue = []
  29. onPlay = null
  30. Number jump = 10
  31. Boolean skip = true
  32. String repeat = 'off'
  33. // the state the media events write (the framework repaints the sites that read them)
  34. String playing = 'false'
  35. String muted = 'false'
  36. String timeText = '0:00'
  37. String totalText = '0:00'
  38. String playedPct = '0'
  39. String bufferedPct = '0'
  40. String speedText = '1'
  41. String dragging = 'false'
  42. String bufferedStyle = 'width:0%'
  43. String playedStyle = 'width:0%'
  44. String thumbStyle = 'left:0%'
  45. String autoPlay = 'false'
  46. String playClass = 'mp-play'
  47. String playLabelNow = playLabel
  48. String playIsNow = playLabel
  49. String muteClass = 'mp-mute'
  50. String muteLabelNow = muteLabel
  51. // "1:23" — whole seconds are enough for a time line
  52. clockText(t) {
  53. if (t == null || t < 0 || t != t) { return '0:00' }
  54. s = t - t % 1
  55. m = (s - s % 60) / 60
  56. sec = s - m * 60
  57. return m + ':' + (sec < 10 ? '0' : '') + sec
  58. }
  59. // the player's own element (the video or audio tag of this component)
  60. mediaOf(node) { return node.closest('media-player').querySelector('video, audio') }
  61. // The media event target, or the current element for the seek bar mount tick.
  62. // Detached elements can still deliver queued events after a kind change; handlers ignore them.
  63. mediaFrom(node) { return node.matches('video, audio') ? node : mediaOf(node) }
  64. // the seek bar of this component
  65. barOf(node) { return node.closest('media-player').querySelector('mp-seek') }
  66. // the media element's buffered end as a percent of its duration
  67. bufferedPctOf(v) {
  68. if (v == null || v.buffered.length == 0 || v.duration == 0 || v.duration == null) { return '0' }
  69. return '' + ((v.buffered.end(v.buffered.length - 1) / v.duration) * 100 - (v.buffered.end(v.buffered.length - 1) / v.duration) * 100 % 1)
  70. }
  71. Style {
  72. mediaPlayer {
  73. display = 'block'
  74. font = 'inherit'
  75. color = 'var(--color-text, #000)'
  76. background = 'var(--color-background, #fff)'
  77. video {
  78. display = 'block'
  79. width = '100%'
  80. aspectRatio = '16 / 9'
  81. height = 'auto'
  82. objectFit = 'contain'
  83. background = 'var(--color-background-sunken, #555)'
  84. borderRadius = 'var(--radius-large, 10px)'
  85. cursor = 'pointer'
  86. }
  87. audio { display = 'none' }
  88. // Class or attribute assigned by the View or code; no compound-selector form.
  89. '.mp-cover' {
  90. display = 'flex'
  91. alignItems = 'center'
  92. gap = '.8rem'
  93. margin = '0 0 .4rem'
  94. img {
  95. flex = 'none'
  96. width = '5rem'
  97. height = '5rem'
  98. objectFit = 'cover'
  99. borderRadius = 'var(--radius-large, 10px)'
  100. background = 'var(--color-surface, #ddd)'
  101. }
  102. h2 {
  103. margin = '0'
  104. fontSize = '1.15rem'
  105. lineHeight = '1.3'
  106. color = 'var(--color-text-strong, #000)'
  107. overflowWrap = 'anywhere'
  108. }
  109. p {
  110. margin = '.15rem 0 0'
  111. color = 'var(--color-text-muted, #555)'
  112. overflowWrap = 'anywhere'
  113. }
  114. }
  115. mpSeek {
  116. display = 'block'
  117. position = 'relative'
  118. height = '2.75rem'
  119. margin = '.15rem 0'
  120. touchAction = 'none'
  121. cursor = 'pointer'
  122. animation = 'media-player-mount 100ms linear infinite'
  123. // Class or attribute assigned by the View or code; no compound-selector form.
  124. '.mp-track' {
  125. position = 'absolute'
  126. left = '.3125rem'
  127. right = '.3125rem'
  128. top = '1.1875rem'
  129. height = '.375rem'
  130. borderRadius = 'var(--radius-small, 5px)'
  131. background = 'var(--color-surface, #ddd)'
  132. overflow = 'hidden'
  133. }
  134. // Class or attribute assigned by the View or code; no compound-selector form.
  135. '.mp-buffered' {
  136. position = 'absolute'
  137. left = '0'
  138. top = '0'
  139. bottom = '0'
  140. width = '0'
  141. background = 'var(--color-grey, #999)'
  142. opacity = '.55'
  143. }
  144. // Class or attribute assigned by the View or code; no compound-selector form.
  145. '.mp-played' {
  146. position = 'absolute'
  147. left = '0'
  148. top = '0'
  149. bottom = '0'
  150. width = '0'
  151. background = 'var(--color-accent, #000)'
  152. }
  153. // Class or attribute assigned by the View or code; no compound-selector form.
  154. '.mp-thumb' {
  155. position = 'absolute'
  156. top = '1.0625rem'
  157. width = '.625rem'
  158. height = '.625rem'
  159. borderRadius = '50%'
  160. background = 'var(--color-accent, #000)'
  161. transform = 'translateX(-50%)'
  162. left = '0'
  163. marginLeft = '.3125rem'
  164. }
  165. }
  166. mpButtons {
  167. display = 'flex'
  168. alignItems = 'center'
  169. flexWrap = 'wrap'
  170. gap = '.2rem'
  171. button {
  172. display = 'inline-flex'
  173. alignItems = 'center'
  174. justifyContent = 'center'
  175. minWidth = '2.75rem'
  176. minHeight = '2.75rem'
  177. padding = '0'
  178. font = 'inherit'
  179. fontWeight = '600'
  180. color = 'var(--color-text, #000)'
  181. background = 'transparent'
  182. border = '0'
  183. borderRadius = 'var(--radius-small, 5px)'
  184. cursor = 'pointer'
  185. hover { background = 'var(--color-surface, #f2f2f2)' }
  186. focusVisible {
  187. outline = '2px solid var(--color-accent, #555)'
  188. outlineOffset = '1px'
  189. }
  190. }
  191. // Class or attribute assigned by the View or code; no compound-selector form.
  192. 'button.mp-play' {
  193. background = 'var(--color-surface, #f2f2f2)'
  194. minWidth = '3.25rem'
  195. minHeight = '3.25rem'
  196. width = '3.25rem'
  197. height = '3.25rem'
  198. }
  199. // Class or attribute assigned by the View or code; no compound-selector form.
  200. '.mp-times' {
  201. display = 'inline-flex'
  202. alignItems = 'center'
  203. minHeight = '2.75rem'
  204. padding = '0'
  205. flex = '0 1 auto'
  206. flexWrap = 'nowrap'
  207. fontVariantNumeric = 'tabular-nums'
  208. fontSize = '.85rem'
  209. whiteSpace = 'nowrap'
  210. color = 'var(--color-text-muted, #555)'
  211. }
  212. }
  213. // Class or attribute assigned by the View or code; no compound-selector form.
  214. '.mp-play' {
  215. // Class or attribute assigned by the View or code; no compound-selector form.
  216. '.i-pause' { display = 'none' }
  217. }
  218. // Class or attribute assigned by the View or code; no compound-selector form.
  219. '.mp-play.is-playing' {
  220. // Class or attribute assigned by the View or code; no compound-selector form.
  221. '.i-play' { display = 'none' }
  222. // Class or attribute assigned by the View or code; no compound-selector form.
  223. '.i-pause' { display = 'inline-flex' }
  224. }
  225. // Class or attribute assigned by the View or code; no compound-selector form.
  226. '.mp-mute' {
  227. // Class or attribute assigned by the View or code; no compound-selector form.
  228. '.i-off' { display = 'none' }
  229. }
  230. // Class or attribute assigned by the View or code; no compound-selector form.
  231. '.mp-mute.is-muted' {
  232. // Class or attribute assigned by the View or code; no compound-selector form.
  233. '.i-on' { display = 'none' }
  234. // Class or attribute assigned by the View or code; no compound-selector form.
  235. '.i-off' { display = 'inline-flex' }
  236. }
  237. // Class or attribute assigned by the View or code; no compound-selector form.
  238. '.mp-queue-title' {
  239. margin = '1rem 0 .2rem'
  240. fontSize = '1rem'
  241. color = 'var(--color-text-strong, #000)'
  242. }
  243. // Class or attribute assigned by the View or code; no compound-selector form.
  244. 'ol.mp-queue' {
  245. display = 'grid'
  246. gap = '.1rem'
  247. margin = '0'
  248. padding = '0'
  249. listStyle = 'none'
  250. li { margin = '0' }
  251. button {
  252. display = 'flex'
  253. alignItems = 'center'
  254. gap = '.5rem'
  255. width = '100%'
  256. minHeight = '2.75rem'
  257. padding = '.3rem .55rem'
  258. font = 'inherit'
  259. textAlign = 'left'
  260. color = 'var(--color-text, #000)'
  261. background = 'transparent'
  262. border = '0'
  263. borderRadius = 'var(--radius-small, 5px)'
  264. cursor = 'pointer'
  265. hover { background = 'var(--color-surface, #f2f2f2)' }
  266. focusVisible {
  267. outline = '2px solid var(--color-accent, #555)'
  268. outlineOffset = '1px'
  269. }
  270. }
  271. // Class or attribute assigned by the View or code; no compound-selector form.
  272. 'li.current' {
  273. button {
  274. color = 'var(--color-accent, #000)'
  275. background = 'var(--color-surface, #f2f2f2)'
  276. }
  277. // Class or attribute assigned by the View or code; no compound-selector form.
  278. '.mp-q-dur' { color = 'inherit' }
  279. }
  280. // Class or attribute assigned by the View or code; no compound-selector form.
  281. '.mp-q-title' {
  282. flex = '1'
  283. minWidth = '0'
  284. overflowWrap = 'anywhere'
  285. textAlign = 'left'
  286. }
  287. // Class or attribute assigned by the View or code; no compound-selector form.
  288. '.mp-q-dur' {
  289. flex = 'none'
  290. fontSize = '.85rem'
  291. color = 'var(--color-text-muted, #555)'
  292. }
  293. }
  294. }
  295. '@keyframes media-player-mount' {
  296. 'from' { opacity = '.999' }
  297. to { opacity = '1' }
  298. }
  299. // No language form for selector list.
  300. 'media-player mp-buttons .i-play, media-player mp-buttons .i-pause, media-player mp-buttons .i-on, media-player mp-buttons .i-off' {
  301. display = 'inline-flex'
  302. flex = 'none'
  303. lineHeight = '0'
  304. }
  305. }
  306. View {
  307. mediaPlayer {
  308. if (isVideo) { video { src = src loop = repeatOne preload = "metadata" playsinline = "playsinline" tabindex = "0" title = title class = "mp-media"
  309. on click(e) { emit mpToggle(e) } on play(e) { emit mpStarted(e) } on pause(e) { emit mpPaused(e) } on ended(e) { emit mpEnded(e) } on timeupdate(e) { emit mpTime(e) } on durationchange(e) { emit mpTotal(e) } on loadedmetadata(e) { emit mpLoad(e) } on progress(e) { emit mpBuffered(e) } on volumechange(e) { emit mpVolume(e) } on ratechange(e) { emit mpRate(e) } on keydown(e) { emit mpKey(e) }
  310. } }
  311. if (isAudio) { audio { src = src loop = repeatOne preload = "metadata" class = "mp-media"
  312. on play(e) { emit mpStarted(e) } on pause(e) { emit mpPaused(e) } on ended(e) { emit mpEnded(e) } on timeupdate(e) { emit mpTime(e) } on durationchange(e) { emit mpTotal(e) } on loadedmetadata(e) { emit mpLoad(e) } on progress(e) { emit mpBuffered(e) } on volumechange(e) { emit mpVolume(e) } on ratechange(e) { emit mpRate(e) } on keydown(e) { emit mpKey(e) }
  313. }
  314. if (hasCover) { div { class = "mp-cover"
  315. img { src = cover alt = "" }
  316. div {
  317. h2 { title }
  318. p { artist }
  319. }
  320. } }
  321. }
  322. mpSeek { role = "slider" 'aria-label' = "Seek" 'aria-valuemin' = "0" 'aria-valuemax' = "100" 'aria-valuenow' = playedPct 'aria-valuetext' = seekText tabindex = "0"
  323. on animationiteration(e) { emit mpMount(e) } on pointerdown(e) { emit mpDown(e) } on pointermove(e) { emit mpMove(e) } on pointerup(e) { emit mpUp(e) } on pointercancel(e) { emit mpUp(e) } on keydown(e) { emit mpBarKey(e) }
  324. div { class = "mp-track"
  325. div { class = "mp-buffered" style = bufferedStyle }
  326. div { class = "mp-played" style = playedStyle }
  327. }
  328. div { class = "mp-thumb" style = thumbStyle }
  329. }
  330. mpButtons {
  331. if (skip) { button { type = "button" class = "mp-back" title = backLabel 'aria-label' = backLabel Icon { name = "skipBack" size = "1.5em" } on click(e) { emit mpBack(e) } } }
  332. button { type = "button" class = playClass title = playLabelNow 'aria-label' = playIsNow
  333. span { class = "i-play" Icon { name = "play" size = "1.75em" } }
  334. span { class = "i-pause" Icon { name = "pause" size = "1.75em" } }
  335. on click(e) { emit mpToggle(e) }
  336. }
  337. if (skip) { button { type = "button" class = "mp-forward" title = forwardLabel 'aria-label' = forwardLabel Icon { name = "skipForward" size = "1.5em" } on click(e) { emit mpForward(e) } } }
  338. span { class = "mp-times"
  339. time { timeText }
  340. span { 'aria-hidden' = "true" "/" }
  341. time { totalText }
  342. }
  343. button { type = "button" class = muteClass title = muteLabelNow 'aria-label' = muteLabelNow
  344. span { class = "i-on" Icon { name = "volume" } }
  345. span { class = "i-off" Icon { name = "volumeOff" } }
  346. on click(e) { emit mpMute(e) }
  347. }
  348. button { type = "button" class = "mp-speed" title = speedLabel 'aria-label' = speedName on click(e) { emit mpSpeed(e) }
  349. span { 'aria-hidden' = "true" speedText + '×' }
  350. }
  351. if (isVideo) { button { type = "button" class = "mp-fullscreen" title = fullscreenLabel 'aria-label' = fullscreenLabel Icon { name = "fullscreen" } on click(e) { emit mpFull(e) } } }
  352. }
  353. if (hasQueue) { div {
  354. h2 { class = "mp-queue-title" queueLabel }
  355. ol { class = "mp-queue" 'aria-label' = queueLabel
  356. for (q of rows) { li { class = q.cls
  357. button { type = "button" 'data-src' = q.src title = q.title
  358. span { class = "mp-q-title" q.title }
  359. span { class = "mp-q-dur" q.dur }
  360. on click(e) { emit mpPick(e) }
  361. }
  362. } }
  363. }
  364. } }
  365. }
  366. }
  367. repeatOne = repeat == 'one'
  368. isVideo = kind != 'audio'
  369. isAudio = kind == 'audio'
  370. hasCover = kind == 'audio' && cover != ''
  371. hasQueue = queue.length > 0
  372. seekText = timeText + ' of ' + totalText
  373. speedName = speedLabel + ' ' + speedText + '×'
  374. Hybrid rows = rowsOf(queue, src)
  375. // the queue rows with the current one marked (a row's class must be a field of the record)
  376. rowsOf(list, now) {
  377. out = []
  378. let i = 0
  379. while (i < list.length) {
  380. out.push({ src = list[i].src title = list[i].title dur = list[i].dur cls = list[i].src == now ? 'current' : '' })
  381. i = i + 1
  382. }
  383. return out
  384. }
  385. // ---- the buttons ----------------------------------------------------------------------------------------
  386. on mpToggle(e) {
  387. v = mediaOf(e.target)
  388. if (v.paused) { v.play() } else { v.pause() }
  389. return null
  390. }
  391. on mpBack(e) {
  392. v = mediaOf(e.target)
  393. if (v.currentTime > jump) { v.currentTime = v.currentTime - jump } else { v.currentTime = 0 }
  394. return null
  395. }
  396. on mpForward(e) {
  397. v = mediaOf(e.target)
  398. if (v.duration > 0 && v.currentTime + jump < v.duration) { v.currentTime = v.currentTime + jump } else if (v.duration > 0) { v.currentTime = v.duration }
  399. return null
  400. }
  401. on mpMute(e) {
  402. v = mediaOf(e.target)
  403. v.muted = !v.muted
  404. return null
  405. }
  406. on mpSpeed(e) {
  407. v = mediaOf(e.target)
  408. s = v.playbackRate
  409. let next = 1
  410. if (s == 1) { next = 1.25 } else if (s == 1.25) { next = 1.5 } else if (s == 1.5) { next = 2 }
  411. v.playbackRate = next
  412. speedText = '' + next
  413. return null
  414. }
  415. on mpFull(e) {
  416. p = e.target.closest('media-player')
  417. if (document.fullscreenElement != null) { document.exitFullscreen() } else { p.requestFullscreen() }
  418. return null
  419. }
  420. // ---- the seek bar ---------------------------------------------------------------------------------------
  421. // the percent of the bar a pointer x lands on
  422. pctOf(bar, x) {
  423. r = bar.getBoundingClientRect()
  424. if (r.width == 0) { return 0 }
  425. let p = (x - r.left) / r.width * 100
  426. if (p < 0) { p = 0 }
  427. if (p > 100) { p = 100 }
  428. return p - p % 1
  429. }
  430. on mpDown(e) {
  431. v = mediaOf(e.target)
  432. bar = barOf(e.target)
  433. bar.setPointerCapture(e.pointerId)
  434. dragging = 'true'
  435. if (v.duration > 0) { v.currentTime = pctOf(bar, e.clientX) / 100 * v.duration }
  436. return null
  437. }
  438. on mpMove(e) {
  439. if (dragging != 'true') { return null }
  440. v = mediaOf(e.target)
  441. bar = barOf(e.target)
  442. if (v.duration > 0) { v.currentTime = pctOf(bar, e.clientX) / 100 * v.duration }
  443. return null
  444. }
  445. on mpUp(e) {
  446. dragging = 'false'
  447. return null
  448. }
  449. // the seek bar itself takes the keyboard too: arrows jump, Home / End go to the ends
  450. on mpBarKey(e) {
  451. v = mediaOf(e.target)
  452. if (e.key == 'ArrowLeft') { e.preventDefault() emit mpBack(e) return null }
  453. if (e.key == 'ArrowRight') { e.preventDefault() emit mpForward(e) return null }
  454. if (e.key == 'Home' && v.duration > 0) { e.preventDefault() v.currentTime = 0 return null }
  455. if (e.key == 'End' && v.duration > 0) { e.preventDefault() v.currentTime = v.duration return null }
  456. return null
  457. }
  458. // ---- the media element's events --------------------------------------------------------------------------
  459. // the whole display read from the media element: the labels, the times, the bars, the play / mute / speed state. A new
  460. // source on the SAME element (a queue item of the same kind) or a new element (the kind changed) must never show the
  461. // old item's state: the time, the bars, the speed and the mute of the element are what the buttons show.
  462. on mpSync(e) {
  463. v = mediaFrom(e.target)
  464. if (!v.isConnected) { return null }
  465. timeText = clockText(v.currentTime)
  466. totalText = v.duration > 0 ? clockText(v.duration) : '0:00'
  467. playedPct = v.duration > 0 ? '' + (v.currentTime / v.duration * 100 - v.currentTime / v.duration * 100 % 1) : '0'
  468. playedStyle = 'width:' + playedPct + '%'
  469. thumbStyle = 'left:' + playedPct + '%'
  470. bufferedPct = bufferedPctOf(v)
  471. bufferedStyle = 'width:' + bufferedPct + '%'
  472. speedText = '' + v.playbackRate
  473. muted = v.muted ? 'true' : 'false'
  474. muteClass = v.muted ? 'mp-mute is-muted' : 'mp-mute'
  475. muteLabelNow = v.muted ? unmuteLabel : muteLabel
  476. playClass = v.paused ? 'mp-play' : 'mp-play is-playing'
  477. playLabelNow = v.paused ? playLabel : pauseLabel
  478. playIsNow = playLabelNow
  479. return null
  480. }
  481. // the metadata of a new source arrived after the handlers were bound (a queue pick of the same kind keeps the element and
  482. // only changes its src; `loadstart` is not a DOM event the framework knows, `loadedmetadata` is): read the display again
  483. // and, when the host asked for it, start the new item
  484. on mpLoad(e) {
  485. if (!e.target.isConnected) { return null }
  486. emit mpSync(e)
  487. v = mediaFrom(e.target)
  488. if (autoPlay == 'true') { v.play() }
  489. return null
  490. }
  491. on mpRate(e) { if (!e.target.isConnected) { return null } speedText = '' + e.target.playbackRate return null }
  492. // the first tick of the mount animation: the element's own state (already loaded before the handlers bound)
  493. // is read in, then the animation is turned off
  494. on mpMount(e) {
  495. e.target.style.animationName = 'none'
  496. emit mpSync(e)
  497. v = mediaOf(e.target)
  498. if (autoPlay == 'true') { v.play() }
  499. return null
  500. }
  501. on mpStarted(e) { if (!e.target.isConnected) { return null } playing = 'true' playClass = 'mp-play is-playing' playLabelNow = pauseLabel playIsNow = pauseLabel return null }
  502. on mpPaused(e) { if (!e.target.isConnected) { return null } playing = 'false' playClass = 'mp-play' playLabelNow = playLabel playIsNow = playLabel return null }
  503. on mpTime(e) {
  504. if (!e.target.isConnected) { return null }
  505. v = e.target
  506. timeText = clockText(v.currentTime)
  507. if (v.duration > 0) {
  508. playedPct = '' + (v.currentTime / v.duration * 100 - v.currentTime / v.duration * 100 % 1)
  509. playedStyle = 'width:' + playedPct + '%'
  510. thumbStyle = 'left:' + playedPct + '%'
  511. if (totalText == '0:00') { totalText = clockText(v.duration) }
  512. bufferedPct = bufferedPctOf(v)
  513. bufferedStyle = 'width:' + bufferedPct + '%'
  514. }
  515. return null
  516. }
  517. on mpTotal(e) {
  518. if (!e.target.isConnected) { return null }
  519. if (e.target.duration > 0) { totalText = clockText(e.target.duration) }
  520. return null
  521. }
  522. on mpBuffered(e) {
  523. if (!e.target.isConnected) { return null }
  524. v = e.target
  525. bufferedPct = bufferedPctOf(v)
  526. bufferedStyle = 'width:' + bufferedPct + '%'
  527. if (v.duration > 0 && totalText == '0:00') { totalText = clockText(v.duration) }
  528. return null
  529. }
  530. on mpVolume(e) {
  531. if (!e.target.isConnected) { return null }
  532. muted = e.target.muted ? 'true' : 'false'
  533. muteClass = muted == 'true' ? 'mp-mute is-muted' : 'mp-mute'
  534. muteLabelNow = muted == 'true' ? unmuteLabel : muteLabel
  535. return null
  536. }
  537. on mpKey(e) {
  538. if (e.key == ' ' || e.key == 'Spacebar') { e.preventDefault() emit mpToggle(e) return null }
  539. if (e.key == 'ArrowLeft') { e.preventDefault() emit mpBack(e) return null }
  540. if (e.key == 'ArrowRight') { e.preventDefault() emit mpForward(e) return null }
  541. return null
  542. }
  543. // ---- the queue ---------------------------------------------------------------------------------------------
  544. // a tap on a queue item tells the host, which hands a new src back (the player is built anew with it)
  545. // a tap on a queue item tells the host, which hands a new src back (the player is built anew with it); the
  546. // new one starts playing at once (the user asked for it — autoplay policies allow a play after a tap)
  547. on mpPick(e) {
  548. b = e.target.closest('button')
  549. if (onPlay != null) { onPlay(b.getAttribute('data-src')) }
  550. return null
  551. }
  552. // an item ended: the next one is picked the same way (the last one just stops)
  553. on mpEnded(e) {
  554. if (!e.target.isConnected) { return null }
  555. playing = 'false'
  556. let i = 0
  557. let next = ''
  558. while (i < queue.length) {
  559. if (queue[i].src == src && i + 1 < queue.length) { next = queue[i + 1].src }
  560. i = i + 1
  561. }
  562. if (next != '' && onPlay != null) { onPlay(next) }
  563. return null
  564. }

Branches

Latest commits

  • 10f8a8c8Merge branch 'code-order' into mainJukebox
  • 204fc828Merge branch 'day72' into mainJukebox
  • 95f5faae|||PR jukebox#7 Drop needless let declarationsmre
  • 33072bb5|||PR Record day72 gates and Chrome proofmre
  • 95f2cd73|||PR Use typed parent methods for screen playback and local server facesmre
  • 6422a020Sync media-player at 51c3818mre
  • b582ba1cVendor complete Hybriel day72 plugin setmre
  • 02dccbc9Merge branch 'records-1119' into mainJukebox
  • a39e1c23|||PR Records: missions 013-015, reconnect fix livemre
  • fc7db075Merge branch 'reconnect-retry' into mainJukebox
  • ac6f4c6fL2: plain declaration for a in pickedNextmre
  • 2f335086Review round 2: only an explicit queue pick drops pend (not the automatic advance); jb23 records every source changemre
  • 3eb6695fReview fixes: action generation, queue pick clears pend, Previous/Next retry the decided request, typed handlersmre
  • 7a53c0c2|||PR A tap lost to a dead socket plays after reconnect (mission 015)mre
  • 1f0cd77bMerge branch 'records-day41' into mainJukebox
  • 67be229f|||PR Records: day41 live (PR #4), mission 012, statusmre
  • 0bb027daconductor: caramboleyo is the user, not owner/creatorApollo
  • 04f5d9d5Merge branch 'day41' into mainJukebox
  • 8ed6da45|||PR README: media-player pin df9e7dfmre
  • d5d45fc3|||PR media-player df9e7df (repeat-one fix), sync pin and SOURCEmre