From c721b50661d2f9c7d1edd7ba997460f51ec4bb58 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Mon, 5 Apr 2021 12:17:26 +0800 Subject: Random bullshit go!!! Finally, add notes to TSOP. --- libs/music/player.d/main_static.js | 59 +++++++++++++++++++++++++++++--------- libs/music/player.d/styles.css | 14 +++++++++ 2 files changed, 59 insertions(+), 14 deletions(-) (limited to 'libs/music/player.d') diff --git a/libs/music/player.d/main_static.js b/libs/music/player.d/main_static.js index 51f7243..cc327d8 100644 --- a/libs/music/player.d/main_static.js +++ b/libs/music/player.d/main_static.js @@ -1,5 +1,6 @@ -//Chris Xiong 2015,2016,2017,2018 +//Chris Xiong 2015-2021 //License: Expat +//WARNING: This file contains profanity (thrown as exceptions). let NSInk=null; let NSAudio=null; @@ -49,10 +50,9 @@ NSPlayer={ load_playlist:async function(pln,ord) { let r=null; - try{ - const resp=await fetch(new Request(`/libs/music/player.d/playlists/${pln}.playlist?${new Date().getTime()}`)); - r=await resp.text(); - }catch(e){return;} + const resp=await fetch(new Request(`/libs/music/player.d/playlists/${pln}.playlist?${new Date().getTime()}`)); + if(!resp.ok)throw "shit"; + r=await resp.text(); let rarr=r.split('\n'); let tarr=[]; const fmt=sh.useFLAC()?'flac':'ogg'; @@ -75,7 +75,11 @@ NSPlayer={ `#${encodeURIComponent(this.plistname)}/${encodeURIComponent(this.tracks[id].title)}`); NSUI.iplaypause.style.backgroundPosition=`${NSUI.bpauserect}`; this.current=id; - NSUI.lbnowplaying.innerHTML=`Now Playing: ${this.tracks[id].title}`; + NSUI.lbnowplaying.innerHTML="Now Playing: "; + const a=sh.newelem("a"); + a.innerHTML=this.tracks[id].title; + a.href=`javascript:NSUI.showNotes("${this.tracks[id].title}")`; + NSUI.lbnowplaying.appendChild(a); if(navigator.mediaSession) navigator.mediaSession.metadata=new MediaMetadata({title:this.tracks[id].title,album:this.plistname}); NSUI.set_highlighted(this.plistname,this.tracks[id].title); @@ -253,10 +257,9 @@ NSUI={ { const moi=this; let r=null; - try{ - const resp=await fetch(new Request(`/libs/music/player.d/playlists/playlists?${new Date().getTime()}`)); - r=await resp.text(); - }catch(e){return;} + const resp=await fetch(new Request(`/libs/music/player.d/playlists/playlists?${new Date().getTime()}`)); + if(!resp.ok)throw "shit"; + r=await resp.text(); let rarr=r.split('\n'); let tarr=[]; let cnt=0; @@ -270,7 +273,7 @@ NSUI={ NSPlayer.load_playlist(t,i).then((rp)=>{ tarr[rp.plistord]=rp; if(--cnt<=0)a(null); - }); + },()=>{b(null);}); } }); await p; @@ -288,7 +291,11 @@ NSUI={ { const ta=NSUI.ulplaylists.childNodes[i].firstChild; if(ta.pid==this.pid) - {ta.classList.add('highlighted');ta.classList.add('active');} + { + if(ta.classList.contains('highlighted')) + NSUI.showNotes(this.innerHTML); + ta.classList.add('highlighted');ta.classList.add('active'); + } else{ta.classList.remove('highlighted');ta.classList.remove('active');} } NSUI.present_playlist.bind(NSUI,this.pid)(); @@ -395,7 +402,28 @@ NSUI={ document.getElementById('timeleft').innerHTML=`-${NSUI.formatTime(NSUI.audio.duration-NSUI.audio.currentTime)}`; document.getElementById('ctime').style.width=NSUI.audio.currentTime/NSUI.audio.duration*100+'%'; NSUI.bufferedUpdate(); - } + }, + showNotes:async function(title) + { + const nd=sh.elem("notes"); + const nt=sh.elem("ntext"); + nt.innerHTML="Loading..." + nd.style.display="block"; + setTimeout(()=>{nd.style.opacity=1.;}); + const url=`//filestorage.chrisoft.org/music/notes/${title}.note`; + try{ + const resp=await fetch(new Request(url)); + if(!resp.ok)throw "shit"; + r=await resp.text(); + nt.innerHTML=r; + }catch(e){nt.innerHTML="This particular track doesn't seem to have a note.";} + }, + hideNotes:function(title) + { + const nd=sh.elem("notes"); + nd.style.opacity=0.; + setTimeout(()=>{nd.style.display="none";},500); + } }; NSAudio={ @@ -711,7 +739,10 @@ function init() } sh.elem('overlay').style.display='none'; } - }); + }, + ()=>{ + sh.elem('overlaytext').innerHTML+="Failed...
Maybe try refreshing the page?" + }); NSVisualization.init();NSInk.inkPrepare(); NSUI.audio.ontimeupdate=NSUI.timeUpdate; NSUI.audio.onended=NSPlayer.next.bind(NSPlayer); diff --git a/libs/music/player.d/styles.css b/libs/music/player.d/styles.css index 354fd45..bcbfee3 100644 --- a/libs/music/player.d/styles.css +++ b/libs/music/player.d/styles.css @@ -24,6 +24,20 @@ top:50%; transform:translateXY(-50%,-50%); } +#notes{ + bottom:0; + right:0; + position:absolute; + width:min(80%,480px); + height:min(80%,300px); + z-index:9; + background-color:rgba(0,0,0,0.6); + transition:opacity 0.3s; + opacity:0; + color:#FFF; + margin:1em; + padding:1em; +} .switches{text-align:center;width:100%;padding:0.25em 0 0.25em 0;} .centered-audio{text-align:center;width:100%;} canvas#cvs{width:100%;height:100%;} -- cgit v1.2.3