/* ---------------- Now Playing ---------------- */ /// Now Playing (#475): what is playing, opened from the player bar. Its artwork large, the /// podcast it is from, its show notes and what follows in Up Next. The bar stays below it with /// the controls, so there is one set of them, not a second to keep in step. const nowSheet=$('#nowsheet'); const nowOpen=()=>!nowSheet.hidden; function openNow(){ if(!player.guid) return; nowSheet.hidden=false; $('#pnow').setAttribute('aria-expanded','true'); drawNow(); $('#nowclose').focus(); } function closeNow(){ if(!nowOpen()) return; nowSheet.hidden=true; $('#pnow').setAttribute('aria-expanded','false'); $('#pnow').focus(); } /// Drawn again whenever what plays or what follows changes, while it is open. function drawNow(){ const e=player.entry; if(!nowOpen()) return; if(!e||!player.guid){ closeNow(); return; } const name=entryName(e).text, show=feedName(e.feed_id); nowSheet.innerHTML=`
${artHTML(e.image||feedArt(e.feed_id),show,'nowart')}

${esc(name)}

${[dateOf(e.published),e.duration?clock(e.duration):''].filter(Boolean).join(', ')}
${upNext.length?`

Up Next

`:''}

Show notes

${textOf(e)}
`; $('#nowclose').onclick=closeNow; $('.nowshow',nowSheet).onclick=()=>{ closeNow(); selectFeed(e.feed_id); }; const q=$('#nowqueue'); for(const x of upNext) q?.appendChild(listenRow(x,'Remove from Up Next',()=>saveUpNext(upNext.filter(y=>entryKey(y)!==entryKey(x))))); drawChapters(); } /// Chapters of what plays (#477), asked for once a file and clock: DeadAir's copy has its own /// times. A failure is forgotten, so the next opening asks again. const chapterLists=new Map>(); let nowChapters: Chapter[]=[]; function chaptersOf(enc: number, deadair: boolean): Promise { const k=`${enc}${deadair?'d':''}`; let got=chapterLists.get(k); if(!got){ got=api(`/api/enclosures/${enc}/chapters${deadair?'?deadair=true':''}`).catch(()=>{ chapterLists.delete(k); return []; }); chapterLists.set(k,got); } return got; } function drawChapters(){ const enc=player.enc; nowChapters=[]; if(enc==null) return; chaptersOf(enc,!!player.src?.includes('/deadair')).then(cs=>{ const box=$('#nowchaps'); if(!box||!nowOpen()||player.enc!==enc||!cs.length) return; nowChapters=cs; box.innerHTML=`

Chapters

    ${cs.map((c,i)=> `
  1. `).join('')}
`; for(const b of $$('button',box)) b.onclick=()=>{ audio.currentTime=cs[Number(b.dataset.i)]!.start; // Marked now: a player still loading says nothing until it plays. markChapter(); if(audio.paused) audio.play(); }; markChapter(); }); } /// The chapter playing now, marked as the one current. function markChapter(){ if(!nowChapters.length||!nowOpen()) return; // A seek to a chapter's start can land a frame before it. const t=audio.currentTime+.25; let at=-1; nowChapters.forEach((c,i)=>{ if(c.start<=t) at=i; }); $$('#nowchaps button').forEach((b,i)=>{ if(i===at) b.setAttribute('aria-current','true'); else b.removeAttribute('aria-current'); }); } audio.addEventListener('timeupdate',markChapter); $('#pnow').onclick=()=>nowOpen()?closeNow():openNow(); $('#pnow').onkeydown=(ev: KeyboardEvent)=>{ if(ev.key==='Enter'||ev.key===' '){ ev.preventDefault(); $('#pnow').click(); } };