From 154b63534baf812bf9a5234774daf09952556285 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Wed, 8 Dec 2021 03:38:10 +0800 Subject: TSOP 2.7.1: help & format switching. Also finally removed all reminiscence of the legacy player. --- libs/music/player.d/main_static.js | 172 ++++++++++++++++++++++--------------- 1 file changed, 105 insertions(+), 67 deletions(-) (limited to 'libs/music/player.d/main_static.js') diff --git a/libs/music/player.d/main_static.js b/libs/music/player.d/main_static.js index 0c3be91..7ac79f1 100644 --- a/libs/music/player.d/main_static.js +++ b/libs/music/player.d/main_static.js @@ -14,9 +14,9 @@ const sh={ newelem:function(e) {return document.createElement(e);}, getcookie:function(key) - {return document.cookie.replace(new RegExp('(?:(?:^|.*;\\s*)'+key+'\\s*\\=\\s*([^;]*).*$)|^.*$'),'$1');}, - useFLAC:function() - {return sh.elem('audio').canPlayType('audio/ogg')=='';} + {return document.cookie.replace(new RegExp('(?:(?:^|.*;\\s*)'+key+'\\s*\\=\\s*([^;]*).*$)|^.*$'),'$2');}, + setcookie:function(key,value) + {return document.cookie=`${key}=${value};max-age=31536000`;}, }; class Ink @@ -47,15 +47,23 @@ NSPlayer={ current:null, shuffle:0, repeat:0, + served_formats:{'ogg':{'mime':'audio/ogg; codecs=vorbis','disp':'ogg 224 kbps'},'flac':{'mime':'audio/flac','disp':'flac'},'opus':{'mime':'audio/ogg; codecs=opus','disp':'opus 96 kbps'},'m4a':{'mime':'audio/aac','disp':'aac 192kbps'}}, + get_preferred_or_default_format:function() + { + if (sh.getcookie('preferredformat') in this.served_formats) + return sh.getcookie('preferredformat'); + for (let fmt in this.served_formats) + if (sh.elem('audio').canPlayType(this.served_formats[fmt].mime)!='') + return fmt; + }, load_playlist:async function(pln,ord) { let r=null; - 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(); + 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'; for(let i=1;i{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); - } + 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.;},5); + 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); + }, + showHelp:function() + { + const hd=sh.elem("helpoverlay"); + hd.style.display="block"; + setTimeout(()=>{hd.style.opacity=1.;},5); + }, + hideHelp:function() + { + const hd=sh.elem("helpoverlay"); + hd.style.opacity=0.; + setTimeout(()=>{hd.style.display="none";},500); + } }; NSAudio={ @@ -721,31 +759,31 @@ NSInk={ function init() { if(!window.devicePixelRatio)window.devicePixelRatio=1; - loadTheme(); + loadTheme(); NSUI.setup_ui(); NSUI.load_playlists() .then(()=>{ sh.elem('overlaytext').innerHTML+="Done!
Click or tap anywhere to start." sh.elem('overlay').onclick=function(){ - try{ + try{ NSAudio.audioInit();NSAudio.connect(); - }catch(e){return;} - if(window.location.hash.length) - { - let p=window.location.hash.substr(1).split('/'); - for(let i=0;i{ - sh.elem('overlaytext').innerHTML+="Failed...
Maybe try refreshing the page?" - }); + ()=>{ + 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); -- cgit v1.2.3