index.html 106 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="apple-mobile-web-app-capable" content="yes" />
  6. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
  7. <meta name="theme-color" content="#4b75ff">
  8. <link rel="stylesheet" href="../script/semantic/semantic.min.css">
  9. <link rel="stylesheet" href="./main.css">
  10. <script src="../script/jquery.min.js"></script>
  11. <script src="../script/ao_module.js"></script>
  12. <script src="../script/semantic/semantic.min.js"></script>
  13. <link rel="icon" type="image/png" href="img/favicon.png" />
  14. <!-- Handle native playback on Chrome Andoird-->
  15. <script src="native.js"></script>
  16. <link rel="manifest" crossorigin="use-credentials" href="manifest.json">
  17. <title>AirMusic</title>
  18. </head>
  19. <body>
  20. <div id="mainMenu" class="ui basic fluid AMmenu menu bottomBlue" style="z-index:80;position:fixed;position:top:0px;left:0px;width:100%;">
  21. <button class="ui item icon noBorder AMmenu button" onClick="toggleLeftMenu();"><i class="content icon"></i></button>
  22. <div class="item noBorder AMmenu" style="padding-right:0px;padding-top:12px;"><i id="AMmenuIcon" class="music icon large whiteFont"></i></div>
  23. <div class="item noBorder AMmenu" style="padding-left:3px;padding-top:3px;padding-bottom:5px;min-width:50%;">
  24. <div class="ui header whiteFont">
  25. <div id="interfaceTitle" style="display:inline; font-weight: lighter;">Music</div>
  26. <div id="interfaceDetails" class="sub header" style="font-size:80%; line-height:1em; color: white;">[0 songs]</div>
  27. </div>
  28. </div>
  29. <button class="ui right item icon AMmenu noBorder button" onClick="enterSearchMode();"><i class="search icon"></i></button>
  30. <!-- <button class="ui right item icon AMmenu noBorder button"><i class="ellipsis vertical icon"></i></button> -->
  31. </div>
  32. <div id="searchModeMenu" class="ui basic fluid AMmenu menu bottomBlue" style="z-index:85;position:fixed;top:0px;left:0px;width:100%;height:51px;display:none;margin-top: 0px;">
  33. <button class="ui item icon noBorder AMmenu button" onClick="exitSearchMode();"><i class="arrow left icon"></i></button>
  34. <div class="ui input" style="flex-grow: 1;">
  35. <input id="searchInputBar" onkeypress="//handleSearchInputEnter(event);" type="text" style="background-color:rgb(48, 48, 48);border:0px !important;border-bottom:2px solid rgb(60, 60, 60) !important;margin-bottom:3px;color:white;" placeholder="Search Music">
  36. </div>
  37. <button class="ui right item icon AMmenu noBorder button" onClick="searchSong();"><i class="search icon"></i></button>
  38. </div>
  39. <!-- The main list that display the current information-->
  40. <div id="mainList">
  41. </div>
  42. <!-- Advance functions config menu-->
  43. <div id="showmoreUIcover" style="position:fixed;left:0px;top:0px;width:100%;height:100%;background:rgba(30,30,30,0.7);z-index:95;display:none;" onClick="hideShowMoreMenu();"></div>
  44. <div id="showMoreUI" class="showMoreMenus" style="display:none;">
  45. <div class="ui large header whiteFont songTitle">N/A</div>
  46. <div class="showMoreMenuItem" onClick="playFromShowMoreMenu();">Play</div>
  47. <div class="showMoreMenuItem" onclick='addToPlaylistFromMoreMenu();'>Add to Playlist</div>
  48. <div class="showMoreMenuItem playlistonly" onclick="removeFromPlylistFromMoreMenu();">Remove from current Playlist</div>
  49. <div class="showMoreMenuItem" onClick="searchYoutubeViaShowMore();">Search on Youtube</div>
  50. <div class="showMoreMenuItem">Edit Tag</div>
  51. <div class="showMoreMenuItem">Share</div>
  52. <div class="showMoreMenuItem" onClick="startRelatedSearch();">Related Search</div>
  53. <div class="showMoreMenuItem" onClick="showFileInfo();">File Information</div>
  54. <div class="topRightCorner songID" align="center" style="margin-top:10px !important;padding-top:3px !important;">-1</div>
  55. </div>
  56. <div id="showFileInfo" class="showMoreMenus" style="display:none;">
  57. <div class="ui large header">
  58. <span class="filename whiteFont">Title</span>
  59. <div class="sub header rawname whiteFont" style="word-break: break-all !important; font-size:80%;">Storage Name</div>
  60. </div>
  61. <div class="ui list whiteFont">
  62. <div class="item whiteFont">Storage Location:   <span class="filepath" style="word-break:break-all;">N/A</span></div>
  63. <div class="item whiteFont">File Size:   <span class="filesize">N/A</span></div>
  64. <div class="item whiteFont">Last Modification Date:   <span class="filedate">N/A</span></div>
  65. </div>
  66. </div>
  67. <!-- Side bar -->
  68. <div id="sideBarCover" style="position:fixed;left:0px;top:0px;width:100%;height:100%;background:rgba(30,30,30,0.7);z-index:50;display:none;" onClick="toggleLeftMenu();"></div>
  69. <div id="leftSideBar" class="leftsb" style="max-width:60%;height:100%;z-index:90;display:none;">
  70. <div class="leftsbObject sidebarBanner">
  71. <img class="ui tiny middle aligned image" src="img/main_icon.png" style="max-width: 50px;"><h5 class="whiteFont" style="display:inline;padding-left:8px;">AirMusic</h5>
  72. </div>
  73. <div class="leftsbObject sbSelectable sbPaddingIn" style="font-size:80%;" onClick="loadSongList();setStorage('viewingTab','music');">
  74. <div class="ui header">
  75. <i class="music tiny icon whiteFont"></i>
  76. <div class="content whiteFont">
  77. Music
  78. </div>
  79. </div>
  80. </div>
  81. <div class="leftsbObject sbSelectable sbPaddingIn" style="font-size:80%;" onClick="loadFolderView();setStorage('viewingTab','folder');">
  82. <div class="ui header">
  83. <i class="folder tiny icon whiteFont"></i>
  84. <div class="content whiteFont">
  85. Folder
  86. </div>
  87. </div>
  88. </div>
  89. <div class="leftsbObject sbSelectable sbPaddingIn" style="font-size:80%;" onClick="loadPlaylistView(); setStorage('viewingTab','playlist');">
  90. <div class="ui header">
  91. <i class="align justify tiny icon whiteFont"></i>
  92. <div class="content whiteFont">
  93. Playlists
  94. </div>
  95. </div>
  96. </div>
  97. <div class="leftsbObject sbSelectable sbPaddingIn" style="font-size:80%;" onClick="loadNetworkView(); setStorage('viewingTab','network');">
  98. <div class="ui header">
  99. <i class="world tiny icon whiteFont"></i>
  100. <div class="content whiteFont">
  101. Network
  102. </div>
  103. </div>
  104. </div>
  105. <!--
  106. <div class="leftsbObject sbSelectable sbPaddingIn" style="font-size:80%;" onClick="">
  107. <div class="ui header">
  108. <i class="upload icon whiteFont"></i>
  109. <div class="content whiteFont">
  110. Upload
  111. </div>
  112. </div>
  113. </div>
  114. -->
  115. <div class="leftsbObject sbSelectable sbPaddingIn" style="font-size:80%;border-top: 2px solid #4a4a4a;" onClick="loadSettingViews();">
  116. <div class="ui header">
  117. <i class="setting tiny icon whiteFont"></i>
  118. <div class="content whiteFont">
  119. Settings
  120. </div>
  121. </div>
  122. </div>
  123. </div>
  124. <!-- Mini player controller put on the bottom side of the list interface-->
  125. <div id="miniPlayer" class="hidden">
  126. <div style="padding-left:20px;padding-top:5px;" >
  127. <div class="ui header selectable" style="margin:0px !important;width:300px;cursor:pointer;" onClick="showMainPlayerInterface();">
  128. <img id="smallPlayerThumb" class="ui small image" src="img/eq.svg" style="margin-right: 0.2em;"></img>
  129. <div class="content whiteFont" style="padding-top:5px;line-height:1em;">
  130. <div id="miniPlayerDisplayName" style="text-overflow: ellipsis;overflow: hidden;max-width:200px; white-space: nowrap;">N/A</div>
  131. <div id="miniPlayerInformation" class="sub header" style="color: #c7c7c7;size:95%;">No information</div>
  132. </div>
  133. </div>
  134. </div>
  135. <div id="miniPlayerIDtab" class="miniPlayer minitab">
  136. 0/0
  137. </div>
  138. <div class="miniPlayerControls">
  139. <button class="miniPlayer selectable" style="font-size:90%; font-weight: lighter;" onClick="previousSong();"><i class="step backward icon whiteFont"></i></button>
  140. <button class="miniPlayer selectable" style="font-size:120%; font-weight: lighter;" onClick="togglePlayMode();"><i class="play icon whiteFont PlayButton"></i></button>
  141. <button class="miniPlayer selectable" style="font-size:90%; font-weight: lighter;" onClick="nextSong();"><i class="step forward icon whiteFont "></i></button>
  142. </div>
  143. </div>
  144. <!-- Main interface for player and audio controller-->
  145. <div id="playerInterface" style="display:none;">
  146. <div id="infoBar" class="whiteFont" style="padding:20px;" align="center">
  147. <!-- Top Information Bar-->
  148. <div class="whiteFont songTitleWrapper" style="margin:0px;display:inline-block;">
  149. <div id="mainPlayerSongTitle" class="whiteFont" style="font-weight: bold;font-size:120%;">Song Title</div>
  150. <small id="mainPlayerSongDesc">This is some small text for display</small>
  151. </div>
  152. <div style="position:absolute;left:20px;top:30px;cursor:pointer;" onClick="hideMainPlayerInterface();">
  153. <i class="large chevron left icon"></i>
  154. </div>
  155. <div style="position:absolute;right:20px;top:30px;cursor:pointer;" onClick='$("#dropdownSonglist").slideDown();'>
  156. <i class="large content icon"></i>
  157. </div>
  158. </div>
  159. <div style="padding-left:20px; padding-right:20px;padding-bottom:5px; position: relative;" align="center">
  160. <!-- Function Menu Bar-->
  161. <div class="ui grid">
  162. <div class="two wide column"><button class="topPanelButtons" style="cursor: pointer;" onclick="showPlaylistInterface();"><i class="large plus icon whiteFont"></i></button></div>
  163. <div class="two wide column"><button class="topPanelButtons" id="downloadBtn" style="cursor: pointer;" onClick="downloadPlayingSong();"><i class="large download icon whiteFont"></i></button></div>
  164. <div class="two wide column"><button class="topPanelButtons" style="cursor: pointer;" onClick="openInFileExplorer();"><i class="large folder open icon whiteFont"></i></button></div>
  165. <div class="two wide column desktopOnly" style="margin-top: -4px;"><button class="topPanelButtons" style="cursor: pointer; opacity: 0.6;" onClick="mute(this);" ><i class="icons"><i class="big red dont icon"></i><i style="margin-left: -3px;" class="large volume off icon whiteFont"></i></i></button></div>
  166. <div class="two wide column desktopOnly"><button class="topPanelButtons" id="voldownBtn" style="cursor: pointer;" onClick="addAudioVolume(-0.05);"><i class="large volume down icon whiteFont"></i></button></div>
  167. <div class="two wide column desktopOnly"><button class="topPanelButtons" id="volupBtn" style="cursor: pointer;" onClick="addAudioVolume(0.05);"><i class="large volume up icon whiteFont"></i></button></div>
  168. <div class="two wide column"><button class="topPanelButtons" style="cursor: pointer;" onClick="showTimerInterface();"><i class="large clock icon whiteFont"></i></button></div>
  169. <div class="two wide column"><button class="topPanelButtons" style="cursor: pointer;" onClick="showSettingInterface();"><i class="large setting icon whiteFont"></i></button></div>
  170. </div>
  171. <div id="volumeGUI" align="center">
  172. <i class="volume off large icon whiteFont" style="position:absolute;left:2em;top:1em;"></i>
  173. <div class="ui tiny progress" style=" margin-top: calc(2em - 5px); margin-bottom: 0; background-color: rgba(255,255,255,0.2);" align="left">
  174. <div id="volBar" class="bar" style="min-width: 0px; width: 40%; height: 10px; background-color: #4b75ff;"></div>
  175. </div>
  176. <i class="volume up large icon whiteFont" style="position:absolute;right:2em;top:1em;"></i>
  177. </div>
  178. </div>
  179. <!-- Download progress bar-->
  180. <div id="downloadProgressBar" class="ui attached fluid tiny progress" style="background-color:rgba(20, 20, 20, 0.9);display:none;">
  181. <div class="bar" style="min-width: 0px; width: 0%;background-color:rgb(75, 117, 255) !important;"></div>
  182. </div>
  183. <div id="albumnArt" align="center">
  184. <img id="albumnArtImage" style="max-width: 80%; pointer-events: none; user-select: none;" src="img/default.png">
  185. </div>
  186. <div id="mainPlayerControlInterface">
  187. <!-- main control interface-->
  188. <div style="width:100%;" align="center">
  189. <div id="progressTime">
  190. 0:00
  191. </div>
  192. <div id="mainPlayerMiniTab" class="mainPlayer minitab">
  193. 0/0
  194. </div>
  195. <div id="remainTime">
  196. -0:00
  197. </div>
  198. </div>
  199. <div style="position:absolute;width:100%;left:0px;bottom:0px;">
  200. <div style="padding-left:10px;padding-right:10px;">
  201. <div class="ui small primary progress" style="background-color: rgba(255,255,255,0.4);">
  202. <div id="audioProgressBar" class="bar" style="min-width: 0px; width: 100%; background: #4b75ff;"></div>
  203. </div>
  204. </div>
  205. <div class="mainControlButtons">
  206. <button class="panelButtons" style="font-size:90%;padding:15px;" onClick="previousSong();"><i class="step backward icon whiteFont"></i></button>
  207. <button class="panelButtons" style="font-size:130%;" onClick="togglePlayMode();"><i class="play icon whiteFont PlayButton"></i></button>
  208. <button class="panelButtons" style="font-size:90%;padding:15px;" onClick="nextSong();"><i class="step forward icon whiteFont "></i></button>
  209. </div>
  210. <div id="randomModeButton" style="position: absolute; left:30px;bottom:20px;" onClick="toggleRandomMode(this);">
  211. <i class="large random icon disabled"></i>
  212. </div>
  213. <div id="repeatModeButton" style="position: absolute; right:30px;bottom:20px;" onClick="toggleRepeatMode(this);">
  214. <i class="large retweet icon disabled"></i>
  215. <p class="whiteFont singleLoop" style="position:absolute;right:0px;bottom:0px;margin-bottom:-13px;margin-right:-2px;display:none;">1</p>
  216. </div>
  217. </div>
  218. </div>
  219. <audio id="mainAudioPlayer" style="display:none;" src=""></audio>
  220. <div id="dropdownSonglist" class="dropdownMusicList" style="display:none;">
  221. <div class="dropdownMusicListMiniMenu">
  222. <i class="icons" style="margin-right:8px;">
  223. <i class="content icon"></i>
  224. <i class="corner music icon" style='color:#333333'></i>
  225. </i>
  226. Now Playing
  227. <div style="position:absolute;top:3px;right:5px;">
  228. [ <span id="dropdownListSongCount">N/A</span> songs / <span id="dropdownListIDCount">N/A</span> MB ] <button onClick='$("#dropdownSonglist").slideUp();' style="cursor:pointer;"><i class="caret up icon whiteFont"></i></button>
  229. </div>
  230. </div>
  231. <div id="currentPlayingMainList" style="overflow-x:hidden;">
  232. </div>
  233. <div class="dropdownMusicListBottom" align="center" onClick='$("#dropdownSonglist").slideUp();'><i class="caret up icon"></i></div>
  234. </div>
  235. </div>
  236. <!-- Quick Menus and other tool windows-->
  237. <!-- Timer control interface-->
  238. <div id="timerInterface" class="quickMenu">
  239. <h4 class="whiteFont">Countdown Timer</h4>
  240. <br>
  241. <div id="timerSettingInterface" style="width:100%;" align="center">
  242. <div>
  243. <div class="ui statistic">
  244. <div class="label whiteFont">hours</div>
  245. <div id="timerHour" class="value whiteFont">0</div>
  246. </div>
  247. <div class="ui statistic">
  248. <div class="label whiteFont">minutes</div>
  249. <div id="timerMinute" class="value whiteFont">0</div>
  250. </div>
  251. </div>
  252. <div>
  253. <div class="ui icon mini buttons">
  254. <button class="ui secondary button" onClick="addTimer('h',1);"><i class="add icon"></i></button>
  255. <button class="ui secondary button" onClick="addTimer('h','r');"><i class="refresh icon"></i></button>
  256. <button class="ui secondary button" onClick="addTimer('h',-1);"><i class="minus icon"></i></button>
  257. </div>
  258. <div class="ui icon mini buttons">
  259. <button class="ui secondary button" onClick="addTimer('m',10);"><i class="add icon"></i></button>
  260. <button class="ui secondary button" onClick="addTimer('m','r');"><i class="refresh icon"></i></button>
  261. <button class="ui secondary button" onClick="addTimer('m',-1);"><i class="minus icon"></i></button>
  262. </div>
  263. </div>
  264. </div>
  265. <div id="timerCountingInterface" style="width:100%; display:none;" align="center">
  266. <div class="ui statistic">
  267. <div id="remainingUI" class="value whiteFont">0:00:00</div>
  268. <div class="label whiteFont">Remaining</div>
  269. </div>
  270. </div>
  271. <div class="ui divider"></div>
  272. <div>
  273. <div class="ui grid">
  274. <div class="eight wide column">
  275. Times up action
  276. </div>
  277. <div class="eight wide column">
  278. <select id="stopMode" class="ui selection mini fluid dropdown">
  279. <option>Fade Out & Stop</option>
  280. <option>Stop Playing</option>
  281. </select>
  282. </div>
  283. </div>
  284. </div>
  285. <div style="width:100%;position:absolute;left:0px;bottom:20px;" align="right">
  286. <div class="ui grid" >
  287. <div class="eight wide column" style="padding-right: 0px;" align="center"><button class="greenBtn fluid" onClick='hideAllquickMenu();'>Close</button></div>
  288. <div class="eight wide column" style="padding-left: 0px;" align="center"><button class="greenBtn fluid" onClick="toggleCountDown(this);">Start</button></div>
  289. </div>
  290. </div>
  291. </div>
  292. <!-- File properties interface-->
  293. <div id="filepropInterface" class="quickMenu">
  294. <div class="ui header">
  295. <span class="filename whiteFont">Title</span>
  296. <div class="sub header rawname whiteFont" style="word-break:break-all;">Storage Name</div>
  297. </div>
  298. <div class="ui list whiteFont">
  299. <div class="item whiteFont">Storage Location:   <span class="filepath" style="word-break:break-all;">N/A</span></div>
  300. <div class="item whiteFont">File Size:   <span class="filesize">N/A</span></div>
  301. <div class="item whiteFont">Last Modification Date:   <span class="filedate">N/A</span></div>
  302. </div>
  303. </div>
  304. <!-- Setting interface-->
  305. <div id="settingInterface" class="quickMenu">
  306. <div style="">
  307. <div class="ui relaxed list" style="padding:0px !important;">
  308. <div id="settingMenuTitle" class="item whiteFont" style="">N/A</div>
  309. <div class="item selectable whiteFont" onclick="showPlaylistInterface(); $('#settingInterface').fadeOut('fast');"><i class="add icon" style="margin-right:5px;"></i> Add to playlist</div>
  310. <div class="item selectable whiteFont" onClick="openInFileExplorer(); hideAllquickMenu();"><i class="folder open icon" style="margin-right:5px;"></i> Open in File Explorer</div>
  311. <div class="item selectable whiteFont" onClick="searchOnYoutube(); hideAllquickMenu();"><i class="youtube play icon" style="margin-right:5px;"></i>Search on Youtube</div>
  312. <div class="item selectable whiteFont" onClick="showFileInformation();"><i class="file icon" style="margin-right:5px;"></i> File Information</div>
  313. <div class="ui divider"></div>
  314. <div id="closeWebAppButton" class="item selectable whiteFont" onClick="ao_module_close();"><i class="remove icon" style="margin-right:5px;"></i> Exit Application</div>
  315. </div>
  316. </div>
  317. </div>
  318. <!-- Playlist interface-->
  319. <div id="playlistInterface" class="quickMenu">
  320. <div class="ui header">
  321. <span class="whiteFont">Add to Playlist</span>
  322. </div>
  323. <div class="playlist item selectable whiteFont" onclick="addToNewPlaylist();">
  324. <i class="add icon whiteFont"></i> New Playlist
  325. </div>
  326. <!-- playlist list-->
  327. <div id="existsingPlaylist" style="overflow-y: scroll; height: 50%; border: 1px solid white;">
  328. <div class="playlist item selectable whiteFont">
  329. <i class="list icon whiteFont"></i> Test Playlist
  330. </div>
  331. </div>
  332. <br>
  333. <div style="width:100%;position:absolute;left:0px;bottom:0px; margin-bottom: 10px;" align="center">
  334. <button class="greenBtn" onClick='hideAllquickMenu();'>Close</button>
  335. </div>
  336. <div class="ui snackbar" id="succSnackBar">
  337. <div class="content">
  338. Action Completed
  339. </div>
  340. </div>
  341. </div>
  342. <!-- Utils Interfaces, usually hidden-->
  343. <div id="fadeReturnScreen" class="fadeScreen whiteFont" onClick="hideAllquickMenu();"></div>
  344. <script>
  345. var leftMenuShown = false;
  346. var currentPath = "";
  347. var currentMode = "music";
  348. var rootPaths = [];
  349. var totalMusicCount = 0;
  350. var currentPlaying = false;
  351. var audioElement = $("#mainAudioPlayer");
  352. var audioElementObject = document.getElementById("mainAudioPlayer"); //Directly expose the audio object
  353. var playingFileDetail = []; //[id, filepath]
  354. var playingSongVpath = ""; //For cache key checking
  355. var displayList = []; //This is the list where the current UI is displaying.
  356. var playingList = []; //This is the list where the player last clicked on an item to play
  357. var pagingEnabled = false; //Enable this when there are too many songs in list
  358. var pagingEnableForPlayingList = false;
  359. var pagingCutoffCount = 100; //No. of songs to start paging
  360. var currentPage = 0;
  361. var currentPlayingPage = 0;
  362. var randomMode = false;
  363. var repeatMode = 0; //Repeat mode 0 -> No repeat, 1 -> Repeat all 2 -> Repeat one
  364. var updateSystemVolume = true;
  365. var timerMode = false;
  366. var timerRemaining = 0;
  367. var playlistAddPendingFile = ""; //The filepath of the file that is pending to be added to playlist
  368. var timerEndMode = "fade"; //Fade or End, Provide volume fadeout or end immediately while times up
  369. var ua = navigator.userAgent.toLowerCase();
  370. var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
  371. var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
  372. var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
  373. var cacheAvailable = 'caches' in self;
  374. let cacheDb, cacheStore, cacheDbTx;
  375. var dbExists = !(!window.indexedDB);
  376. //Init database connection if indexedDB Exists
  377. if (dbExists){
  378. let cacheDbConn = window.indexedDB.open('airmusic', 4);
  379. cacheDbConn.onupgradeneeded = function(event) {
  380. cacheDb = event.target.result;
  381. cacheDbTx = event.target.transaction;
  382. cacheStore = cacheDb.createObjectStore("files",{keyPath:"filename"});
  383. cacheStore = cacheDb.createObjectStore("thumblist",{keyPath:"filename"});
  384. };
  385. cacheDbConn.onerror = function(event) {
  386. console.log("ERROR: " + event.target.errorCode)
  387. };
  388. cacheDbConn.onsuccess = function(event) {
  389. cacheDb = event.target.result
  390. //Database connection established.
  391. //Clear old cache in the system if any
  392. clearExpiredCache();
  393. }
  394. }
  395. //Embed native mediaSession for any device that supports it
  396. initNativeMediaPlayer();
  397. //Update implementatio nof user agent detection
  398. if (typeof InstallTrigger !== 'undefined'){
  399. ua = "firefox";
  400. }
  401. if (!!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime)){
  402. ua = "chrome";
  403. }
  404. var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  405. if (isSafari == true){
  406. ua = "safari";
  407. }
  408. $(document).ready(function(){
  409. $("#leftSideBar").animate({left: $("#leftSideBar").width() * -1}, 300);
  410. //Update 7-8-2019, default loading tab is handled over to the returnToPreviousState() function.
  411. //loadSongList();
  412. //Initiate the module's volume to the system's
  413. syncSystemVol();
  414. initAudioListeners();
  415. resizeQuickAdjust(); //Adjust all the DOM items position according to window size
  416. restoreAllSettings(); //Restore all user prefered settings from storage
  417. hideMainPlayerInterface();//Hide the main interface
  418. setTimeout(function(){
  419. $("#playerInterface").show(); //Only show this interface after it has been out of the working area.
  420. },500);
  421. //Hide the exit application button if it is not in Virtual Desktop Mode
  422. if (!ao_module_virtualDesktop){
  423. $("#closeWebAppButton").hide();
  424. }
  425. returnToPreviousState(); //Try to return to previous state using the window hash value
  426. });
  427. function returnToPreviousState(){
  428. var hash = window.location.hash;
  429. if (hash != ""){
  430. //There are state to restore. Restore using the given hash value
  431. hash = decodeURIComponent(hash.substring(1));
  432. var previousState = JSON.parse(hash);
  433. console.log(previousState);
  434. var currentPath = previousState.path;
  435. var playingFileDetail = previousState.pfp;
  436. var initPauseState = previousState.pause;
  437. if (currentPath != ""){
  438. //Create a dummy folder and trick the system to load to the previous states
  439. var a = '<div></div>';
  440. a = $(a).attr("filepath",currentPath);
  441. openFolder(a[0],{playIDAfterOpen: playingFileDetail[0],startPaused: initPauseState});
  442. }else{
  443. //currentpath is empty, aka Music Mode
  444. loadSongList();
  445. }
  446. }else{
  447. //No state to restore. Restore Viewing Tab instead.
  448. var vt = loadStorage("viewingTab");
  449. if (vt != ""){
  450. if (vt == "music"){
  451. loadSongList();
  452. }else if(vt == "folder"){
  453. loadFolderView();
  454. }else if(vt == "playlist"){
  455. loadPlaylistView();
  456. }else if(vt == "network"){
  457. loadNetworkView();
  458. }
  459. }else{
  460. //Default action
  461. loadSongList();
  462. }
  463. }
  464. }
  465. function loadNetworkView(){
  466. currentMode = "network";
  467. togglePagingMode(false);
  468. }
  469. function loadSettingViews(){
  470. currentMode = "playlist";
  471. //Clear the main list
  472. $("#mainList").html("");
  473. togglePagingMode(false);
  474. //Render the elements
  475. $("#mainList").append(`<div class="mainList item">HELLO WORLD</div>`);
  476. hideLeftMenu();
  477. //Update the headers
  478. $("#interfaceTitle").text("Settings");
  479. $("#AMmenuIcon").attr("class","setting large icon whiteFont");
  480. $("#interfaceDetails").text("Work in progress");
  481. }
  482. function togglePagingMode(enabled=false){
  483. if (pagingEnabled != enabled){
  484. currentPage = 0;
  485. }
  486. pagingEnabled = enabled;
  487. }
  488. function initAudioListeners(){
  489. //Initiate audio progress bar and link it to the progress bar on the main player interface
  490. audioElement[0].addEventListener("timeupdate", function() {
  491. var currentTime = audioElement[0].currentTime;
  492. var duration = audioElement[0].duration;
  493. $('#audioProgressBar').css('width',((currentTime +.25)/duration)*100 + '%');
  494. updatePlaybackDisplayTime(currentTime,duration);
  495. });
  496. audioElement[0].onended = function() {
  497. nextSongHandler();
  498. };
  499. //Handle clicks on progress bar to skip through the playback
  500. $("#audioProgressBar").parent().on("click",function(e){
  501. var duration = audioElement[0].duration;
  502. var jumpTo = (e.offsetX / $(this).width()) * duration;
  503. if (!audioElement[0].paused){
  504. audioElement[0].pause();
  505. audioElement[0].currentTime = jumpTo;
  506. audioElement[0].play();
  507. }else{
  508. audioElement[0].currentTime = jumpTo;
  509. }
  510. });
  511. }
  512. function restoreAllSettings(){
  513. //Repeat mode setting
  514. var strRmode = loadStorage("repeatMode");
  515. if (strRmode != ""){
  516. repeatMode = parseInt(strRmode);
  517. setRepeatMode(repeatMode,$("#repeatModeButton")[0]);
  518. }
  519. //Random Mode setting
  520. var random = loadStorage("randomMode");
  521. if (random != ""){
  522. if (random == "true"){
  523. //random Mode is true when loaded from configuration. Toggle once to match the setting
  524. toggleRandomMode($("#randomModeButton")[0]);
  525. }
  526. }
  527. //Timer mode setting
  528. var TEM = loadStorage("timerEndMode");
  529. if (TEM != ""){
  530. if (TEM == "fade"){
  531. $("#stopMode").val("Fade Out & Stop");
  532. }else{
  533. $("#stopMode").val("Stop Playing");
  534. }
  535. }
  536. }
  537. //Setting menu function
  538. function searchOnYoutube(filename = ""){
  539. if (filename == ""){
  540. var filename = $("#mainPlayerSongTitle").text().trim();
  541. }
  542. var url = "https://www.youtube.com/results?search_query=" + filename ;
  543. window.open(url);
  544. }
  545. //Searching related functions
  546. var preSearchItemBuffer = "";
  547. var searchModeEnabled = false;
  548. var previousPagingEnabled = false;
  549. function enterSearchMode(){
  550. if (searchModeEnabled){
  551. //Search mode already enabled
  552. return;
  553. }
  554. previousPagingEnabled = pagingEnabled;
  555. togglePagingMode(false);
  556. $("#searchModeMenu").show();
  557. $("#mainMenu").hide();
  558. let previousDisplayList = Array.from(displayList);
  559. preSearchItemBuffer = [$("#mainList").html(),$("#interfaceTitle").text(),$("#AMmenuIcon").attr("class"), $("#interfaceDetails").html(), previousDisplayList];
  560. searchModeEnabled = true;
  561. }
  562. function exitSearchMode(){
  563. $("#searchModeMenu").hide();
  564. $("#mainMenu").show();
  565. $("#searchInputBar").val("");
  566. if (preSearchItemBuffer != ""){
  567. //If previous record exists, recover the previous view from storage
  568. $("#mainList").html(preSearchItemBuffer[0]);
  569. $("#interfaceTitle").text(preSearchItemBuffer[1]);
  570. $("#AMmenuIcon").attr("class",preSearchItemBuffer[2]);
  571. $("#interfaceDetails").html(preSearchItemBuffer[3]);
  572. displayList = preSearchItemBuffer[4];
  573. preSearchItemBuffer = "";
  574. }
  575. if (previousPagingEnabled){
  576. togglePagingMode(true);
  577. }
  578. searchModeEnabled = false;
  579. }
  580. document.getElementById("searchInputBar").addEventListener("keypress", function(event){
  581. console.log(event, event.keyCode);
  582. if(event.keyCode == 13){
  583. //Enter pressed. start searching
  584. searchSong();
  585. }
  586. });
  587. /*
  588. function handleSearchInputEnter(e){
  589. if(e.keyCode == 13){
  590. //Enter pressed. start searching
  591. searchSong();
  592. }
  593. }
  594. */
  595. function searchSong(){
  596. var keyword = $("#searchInputBar").val();
  597. if (keyword.includes("?") || keyword.includes("&")){
  598. alert("Search keyword cannot contains & or ? symbol.");
  599. return;
  600. }
  601. if (keyword == ""){
  602. //Empty keyword. Return nothing
  603. return;
  604. }
  605. //Clear the mainList, replace with a dummy loading screen
  606. $("#mainList").html('<div class="mainList item whiteFont">\
  607. <div class="ui header" style="margin:0px !important;padding-bottom:15px;padding-top:5px;">\
  608. <i class="loading spinner icon whiteFont" style="overflow:hidden;margin-top:5px;"></i>\
  609. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%;">\
  610. Searching...\
  611. </div>\
  612. </div>\
  613. <div class="topRightCorner" align="center">\
  614. -1\
  615. </div>\
  616. </div>');
  617. ao_module_agirun("Music/functions/listSong.js", {
  618. listSong: "search:" + keyword
  619. }, function(data){
  620. currentPath = "";
  621. var template = '<div class="mainList file item" filepath={filepath} id={id} rawname={rawname}>\
  622. <div class="ui header selectable" style="margin:0px !important;" onClick="playSong(this);">\
  623. <img class="ui small image" src="img/eq.svg" style="margin-right: 0.2em;"></img>\
  624. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%;">\
  625. {songtitle}\
  626. <div class="sub header fileinfo" style="color: #c7c7c7;">{ext} / {size}</div>\
  627. </div>\
  628. </div>\
  629. <div class="topRightCorner" align="center">\
  630. {id}\
  631. </div>\
  632. <div class="mainList rightFunctionBar" align="center" onClick="showMore(this);">\
  633. <i class="ellipsis vertical icon" style="top: 2em;"></i>\
  634. </div>\
  635. </div>';
  636. if ($("#searchModeMenu").is(":hidden")){
  637. //The user exited search mode before the search results come back
  638. //Dispose the search result
  639. return;
  640. }
  641. if (data.length == 0){
  642. //No search results.
  643. $("#mainList").html("");
  644. $("#mainList").append('<div class="mainList item whiteFont">\
  645. <div class="ui header" style="margin:0px !important;padding-bottom:15px;padding-top:5px;">\
  646. <i class="remove icon whiteFont" style="overflow:hidden;margin-top:5px;"></i>\
  647. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%;">\
  648. No result for keyword: ' + keyword + '.\
  649. </div>\
  650. </div>\
  651. <div class="topRightCorner" align="center">\
  652. -1\
  653. </div>\
  654. </div>');
  655. return;
  656. }
  657. $("#interfaceTitle").text("Search");
  658. $("#AMmenuIcon").attr("class","search icon large whiteFont")
  659. //Initialize the song list
  660. displayList = data;
  661. if (playingList == []){
  662. playingList = Array.from(displayList);
  663. pagingEnableForPlayingList = pagingEnabled;
  664. currentPlayingPage = currentPage;
  665. }
  666. $("#mainList").html("");
  667. for ( var i =0; i < data.length; i++){
  668. var songInfo = data[i];
  669. var path = songInfo[0];
  670. var displayname = ao_module_codec.decodeUmFilename(songInfo[1]);
  671. var ext = songInfo[2];
  672. var size = songInfo[3];
  673. var box = template;
  674. box = replaceAll("{filepath}",ao_module_utils.objectToAttr(path),box);
  675. box = replaceAll("{id}",i + 1,box); //User count from 1
  676. box = replaceAll("{rawname}",ao_module_utils.objectToAttr(songInfo[1]),box);
  677. box = replaceAll("{songtitle}",displayname,box);
  678. box = replaceAll("{ext}",ext,box);
  679. box = replaceAll("{size}",size,box);
  680. $("#mainList").append(box);
  681. }
  682. totalMusicCount = data.length;
  683. $("#mainList").append("<br><br><br><br><br><br><br>");
  684. $("#interfaceDetails").text("[" + i + " songs]");
  685. highLightPlayingMusic();
  686. loadThumbnailToMusicList(".mainList.file.item");
  687. });
  688. }
  689. function enterRemotePlayID(object){
  690. var id = $(object).text().trim();
  691. $("#remotePlayID").val($("#remotePlayID").val() + id);
  692. }
  693. function ridOpr(opr){
  694. if (opr == 'backspace'){
  695. var currentText = $("#remotePlayID").val();
  696. var newText = currentText.substring(0,currentText.length - 1);
  697. $("#remotePlayID").val(newText);
  698. }else if (opr == 'reset'){
  699. $("#remotePlayID").val("");
  700. }
  701. }
  702. function openInFileExplorer(){
  703. var dirname = playingFileDetail[1].split("/");
  704. var fname = dirname.pop(); //Pop away the filename
  705. dirname = dirname.join("/") + "/";
  706. var path = dirname;
  707. if (dirname.substring(0,1) != "/"){
  708. //This is not absolute path. Start the path from airMusic
  709. path = "AirMusic/" + dirname;
  710. }
  711. path = path.replace("media?file=","");
  712. if (path.substring(0,1) == "/"){
  713. path = path.substring(1)
  714. }
  715. ao_module_openPath(path, fname);
  716. }
  717. //quickmenu Functions
  718. function hideAllquickMenu(){
  719. $(".quickMenu").fadeOut('fast');
  720. $("#fadeReturnScreen").fadeOut('fast');
  721. }
  722. //Setting related function
  723. function showSettingInterface(){
  724. $("#settingInterface").fadeIn('fast');
  725. $("#fadeReturnScreen").fadeIn('fast');
  726. //Update contents in the setting menu
  727. $("#settingMenuTitle").text($("#mainPlayerSongTitle").text());
  728. }
  729. //Timer related functions
  730. function showTimerInterface(){
  731. $("#timerInterface").fadeIn('fast');
  732. $("#fadeReturnScreen").fadeIn('fast');
  733. }
  734. function initPlaylistInterfaceList(){
  735. $("#existsingPlaylist").html("");
  736. //Get the playlist list from server side
  737. ao_module_agirun("Music/functions/playlist.js", {
  738. opr: "root"
  739. }, function(data){
  740. data.forEach(playlist => {
  741. $("#existsingPlaylist").append(`<div class="playlist item selectable whiteFont" name="${playlist.name}" onclick="addSongToSelectedPlaylist(this);">
  742. <i class="list icon whiteFont"></i> ${playlist.name} [${playlist.count} files]
  743. </div>`);
  744. })
  745. });
  746. }
  747. function showPlaylistInterface(){
  748. initPlaylistInterfaceList();
  749. $("#playlistInterface").fadeIn('fast');
  750. $("#fadeReturnScreen").fadeIn('fast');
  751. }
  752. function addToThisPlaylist(){
  753. }
  754. $("#stopMode").change(function () {
  755. var end = this.value;
  756. if (end.includes("Fade Out & Stop")){
  757. //Start fading out the volume
  758. timerEndMode = "fade";
  759. setStorage("timerEndMode","fade");
  760. }else{
  761. //End immediately
  762. timerEndMode = "end";
  763. setStorage("timerEndMode","end");
  764. }
  765. });
  766. var fadeOutStepping = 0.1; //The steps size for fading out during timer countdown
  767. var defaultVolumeBeforeFadeout = 0;
  768. function toggleCountDown(button){
  769. if (!timerMode){
  770. //Start count down
  771. timerMode = true;
  772. $(button).text("Stop");
  773. timerRemaining = ((parseInt($("#timerHour").text()) * 60) + parseInt($("#timerMinute").text())) * 60; //in seconds
  774. if (timerRemaining <= 0){
  775. //Start with 0
  776. timerMode = false;
  777. $(button).text("Start");
  778. return;
  779. }
  780. //Update the value on the remaining counter
  781. $("#remainingUI").text(parseTimer(timerRemaining));
  782. $("#timerSettingInterface").slideUp('fast');
  783. $("#timerCountingInterface").slideDown('fast');
  784. $("#stopMode").attr("disabled","");
  785. defaultVolumeBeforeFadeout = audioElement[0].volume;
  786. fadeOutStepping = (audioElement[0].volume) / timerRemaining;
  787. progressCounter();
  788. }else{
  789. //Stop count down
  790. timerMode = false;
  791. $(button).text("Start");
  792. timerRemaining = 0;
  793. $("#timerSettingInterface").slideDown('fast');
  794. $("#timerCountingInterface").slideUp('fast');
  795. $("#stopMode").removeAttr("disabled");
  796. }
  797. }
  798. function progressCounter(){
  799. //Update the timer
  800. timerRemaining = timerRemaining - 1;
  801. $("#remainingUI").text(parseTimer(timerRemaining));
  802. if (timerRemaining > 0){
  803. //Continues
  804. if (timerEndMode == "fade"){
  805. var newvol = audioElement[0].volume - fadeOutStepping;
  806. audioElement[0].volume = Math.max(0,newvol);
  807. }
  808. setTimeout(progressCounter,1000);
  809. }else{
  810. //Times up
  811. handleTimerEnd();
  812. }
  813. }
  814. function handleTimerEnd(){
  815. //Stop the playback
  816. originalVol = audioElement[0].volume;
  817. fadeAudio();
  818. setPlaying(false);
  819. audioElement[0].pause();
  820. setTimeout(function(){
  821. audioElement[0].volume = defaultVolumeBeforeFadeout;
  822. },500);
  823. }
  824. function parseTimer(remainingTime){
  825. //remainingTime in seconds, prase to HH:mm:ss
  826. var hours = Math.floor(remainingTime / 3600);
  827. var remainingTime = remainingTime % 3600;
  828. var minutes = Math.floor(remainingTime / 60);
  829. var seconds = remainingTime % 60;
  830. if (minutes < 10){
  831. minutes = "0" + minutes;
  832. }
  833. if (seconds < 10){
  834. seconds = "0" + seconds;
  835. }
  836. var formatted = hours + ":" + minutes + ":" + seconds;
  837. return formatted;
  838. }
  839. function addTimer(unit,value){
  840. if (unit == "h"){
  841. if (value == "r"){
  842. $("#timerHour").text("0");
  843. }else{
  844. $("#timerHour").text($("#timerHour").text() - -1 * value);
  845. }
  846. }else if (unit == "m"){
  847. if (value == "r"){
  848. $("#timerMinute").text("0");
  849. }else{
  850. $("#timerMinute").text($("#timerMinute").text() - -1 * value);
  851. }
  852. }
  853. if (parseInt($("#timerHour").text()) < 0){
  854. $("#timerHour").text("0");
  855. }
  856. if (parseInt($("#timerMinute").text()) < 0){
  857. if (parseInt($("#timerHour").text()) > 0){
  858. //subtract 1 from the hour
  859. $("#timerHour").text($("#timerHour").text() - 1);
  860. $("#timerMinute").text(parseInt($("#timerMinute").text()) + 60);
  861. }else{
  862. //There is no hours to subtract
  863. $("#timerMinute").text("0");
  864. }
  865. }
  866. if (parseInt($("#timerMinute").text()) > 59){
  867. $("#timerMinute").text(parseInt($("#timerMinute").text()) - 60);
  868. $("#timerHour").text($("#timerHour").text() - -1);
  869. }
  870. }
  871. //Download function
  872. function downloadPlayingSong(){
  873. var url = audioElement.attr("src");
  874. var ext = url.split(".").pop();
  875. var filename = $("#mainPlayerSongTitle").text().trim();
  876. generateDownloadElement(url,filename);
  877. /*
  878. if (url.includes("/media")){
  879. blobDownloadElement(url,filename);
  880. }else{
  881. generateDownloadElement(url,filename);
  882. }
  883. */
  884. }
  885. var downloadInProgress = false;
  886. function blobDownloadElement(filepath,filename){
  887. if (downloadInProgress){
  888. alert("Please wait until another download finished.");
  889. return;
  890. }
  891. downloadInProgress = true;
  892. $("#downloadBtn").find("i").addClass("disabled");
  893. $("#downloadProgressBar").find(".bar").css("width","0%");
  894. $("#downloadProgressBar").show();
  895. var xhr = new XMLHttpRequest();
  896. xhr.onreadystatechange = function(){
  897. if (this.readyState == 4 && this.status == 200){
  898. //handler(this.response);
  899. //console.log(this.response, typeof this.response);
  900. var url = window.URL || window.webkitURL;
  901. //Open the downloaded data in new window for testing
  902. //window.open(url.createObjectURL(this.response));
  903. generateDownloadElement(url.createObjectURL(this.response),filename);
  904. $("#downloadBtn").find("i").removeClass("disabled");
  905. $("#downloadProgressBar").hide();
  906. downloadInProgress = false;
  907. }
  908. }
  909. xhr.onprogress = function (event) {
  910. console.log("[AirMusic] Download Progress: " + event.loaded + " / " + event.total + "Bytes");
  911. $("#downloadProgressBar").find(".bar").css("width",(event.loaded / event.total) * 100 + "%");
  912. };
  913. xhr.open('GET', filepath);
  914. xhr.responseType = 'blob';
  915. xhr.send();
  916. }
  917. function generateDownloadElement(filepath, filename){
  918. var link = document.createElement('a');
  919. //Clean the filepath
  920. filepath = filepath.split("//").join("/");
  921. //Convert the filepath to download path
  922. link.href = filepath.replace("/media?file=", "/media/download/?file=");
  923. //Generate the download element
  924. link.setAttribute('download', filename);
  925. document.getElementsByTagName("body")[0].appendChild(link);
  926. // Firefox
  927. if (document.createEvent) {
  928. var event = document.createEvent("MouseEvents");
  929. event.initEvent("click", true, true);
  930. link.dispatchEvent(event);
  931. }
  932. // IE
  933. else if (link.click) {
  934. link.click();
  935. }
  936. link.parentNode.removeChild(link);
  937. }
  938. //Volume control related features
  939. var previousAudioVolume = 0;
  940. function mute(button){
  941. if (audioElement[0].volume != 0){
  942. //Set to mute
  943. previousAudioVolume = audioElement[0].volume;
  944. audioElement[0].volume = 0;
  945. $(button).css("opacity", "1");
  946. $("#voldownBtn").addClass("disabled");
  947. $("#volupBtn").addClass("disabled");
  948. }else{
  949. //Restore from mute
  950. audioElement[0].volume = previousAudioVolume;
  951. $(button).css("opacity", "0.6");
  952. $("#voldownBtn").removeClass("disabled");
  953. $("#volupBtn").removeClass("disabled");
  954. }
  955. $("#volBar").css("width",audioElement[0].volume * 100 + "%");
  956. }
  957. var volbarTimeoutEvt;
  958. function addAudioVolume(value){
  959. $("#volumeGUI").slideDown('fast');
  960. if (volbarTimeoutEvt !== undefined){
  961. clearTimeout(volbarTimeoutEvt);
  962. }
  963. volbarTimeoutEvt = setTimeout(function(){
  964. $("#volumeGUI").slideUp('fast');
  965. },3000);
  966. $("#volumeGUI")
  967. if (audioElement[0].volume + value >= 1){
  968. audioElement[0].volume = 1;
  969. }else if (audioElement[0].volume + value <= 0){
  970. audioElement[0].volume = 0;
  971. }else{
  972. audioElement[0].volume += value;
  973. }
  974. $("#volBar").css("width",Math.min(100,audioElement[0].volume * 100) + "%");
  975. }
  976. function updatePlaybackDisplayTime(currentTime,duration){
  977. let progress = Math.round(currentTime);
  978. let remainTime = Math.round(duration - currentTime);
  979. $("#progressTime").text(secondsToHms(progress));
  980. if (!isNaN(remainTime)){
  981. $("#remainTime").text("-" + secondsToHms(remainTime));
  982. }
  983. }
  984. function nextSongHandler(){
  985. console.log("Next song");
  986. if (repeatMode == 1){
  987. //Next song in the playlist
  988. if (randomMode){
  989. var randomTrackID = Math.floor(Math.random() * (playingList.length - 1));
  990. //console.log(randomTrackID, playingList[randomTrackID]);
  991. nextSong(randomTrackID,true);
  992. }else{
  993. var playingSongIndex = playingFileDetail[0];
  994. var nextSongIndex = playingSongIndex;
  995. if (nextSongIndex >= playingList.length){
  996. nextSongIndex = 0;
  997. }
  998. //console.log(playingSongIndex, nextSongIndex);
  999. nextSong(nextSongIndex,true);
  1000. }
  1001. }else if (repeatMode == 2){
  1002. //Loop this song only
  1003. audioElement[0].pause();
  1004. audioElement[0].currentTime = 0;
  1005. audioElement[0].play();
  1006. }else if (repeatMode == 0){
  1007. //Pause after finish this song
  1008. setPlaying(false);
  1009. audioElement[0].pause();
  1010. audioElement[0].currentTime = 0;
  1011. }
  1012. }
  1013. function mainPlayerShown(){
  1014. if ($("#playerInterface").offset().left == 0){
  1015. return true;
  1016. }
  1017. return false;
  1018. }
  1019. function toggleRandomMode(button){
  1020. var btn = $(button).find("i");
  1021. if (randomMode){
  1022. //Set the random mode to false
  1023. btn.removeClass("enabled").addClass("disabled");
  1024. randomMode = false;
  1025. }else{
  1026. btn.removeClass("disabled").addClass("enabled");
  1027. randomMode = true;
  1028. }
  1029. setStorage("randomMode",randomMode);
  1030. }
  1031. function toggleRepeatMode(button){
  1032. if (repeatMode == 0){
  1033. setRepeatMode(1,button);
  1034. setStorage("repeatMode",1);
  1035. }else if (repeatMode == 1){
  1036. setRepeatMode(2,button);
  1037. setStorage("repeatMode",2);
  1038. }else if (repeatMode == 2){
  1039. setRepeatMode(0,button);
  1040. setStorage("repeatMode",0);
  1041. }
  1042. }
  1043. function setRepeatMode(modeCode,button){
  1044. if (modeCode == 1){
  1045. //Set repeat mode to "Repeat all"
  1046. $(button).find(".singleLoop").hide();
  1047. $(button).find("i").removeClass("disabled").addClass("enabled");
  1048. repeatMode = 1;
  1049. }else if (modeCode == 2){
  1050. //Set repeat mode to "Repeat one"
  1051. $(button).find(".singleLoop").show();
  1052. $(button).find("i").removeClass("disabled").addClass("enabled");
  1053. repeatMode = 2;
  1054. }else if (modeCode == 0){
  1055. //Set repeat mode to "None"
  1056. $(button).find(".singleLoop").hide();
  1057. $(button).find("i").removeClass("enabled").addClass("disabled");
  1058. repeatMode = 0;
  1059. }
  1060. }
  1061. function hideMainPlayerInterface(){
  1062. $("#playerInterface").animate({left: window.innerWidth},300);
  1063. $("body").css("overflow-y","auto");
  1064. }
  1065. function showMainPlayerInterface(){
  1066. $("#playerInterface").animate({left:0},300);
  1067. $("body").css("overflow-y","hidden");
  1068. }
  1069. function syncSystemVol(){
  1070. //Initiate the module's volume to the system's
  1071. var globalvol = localStorage.getItem("global_volume");
  1072. //console.log("Global Volume" + globalvol.toString());
  1073. if (!globalvol){
  1074. globalvol = 0.1;
  1075. }
  1076. //Check if it is mobile. If yes, always 100% and leave volume to system
  1077. if (isMobile()){
  1078. globalvol = 1;
  1079. //$(".desktopOnly").addClass("disabled");
  1080. }
  1081. audioElement[0].volume = parseFloat(globalvol);
  1082. $("#volBar").css("width",audioElement[0].volume * 100 + "%");
  1083. }
  1084. function replaceAll(target, replace, original){
  1085. return original.split(target).join(replace);
  1086. };
  1087. function playSong(object, startPaused = false){
  1088. if ($(object).parent().hasClass("playingTrack")){
  1089. //This is already the song that is currently playing. Show the main player interface instead.
  1090. showMainPlayerInterface();
  1091. resizeQuickAdjust();
  1092. return;
  1093. }
  1094. //$(".playingTrack").removeClass("playingTrack");
  1095. //$(object).parent().addClass("playingTrack");
  1096. var filepath = ao_module_utils.attrToObject($(object).parent().attr('filepath'));
  1097. var rawname = ao_module_utils.attrToObject($(object).parent().attr('rawname'));
  1098. var displayName = ao_module_codec.decodeUmFilename(rawname);
  1099. var info = $(object).parent().find(".fileinfo").text();
  1100. var id = $(object).parent().attr('id');
  1101. if (id === undefined){
  1102. //This might be a file from dropdown list. use listid instead
  1103. id = $(object).parent().attr('listid');
  1104. }
  1105. updateMiniPlayerUI(displayName,info,id);
  1106. //Check if page mode is enabled. If yes, do auto tab switch
  1107. if (pagingEnabled){
  1108. var targetPageNumber = getPageNumberByPlaybackId(parseInt(id));
  1109. switchToPage(targetPageNumber);
  1110. }
  1111. //Seperate out the filepath without media server path
  1112. var fileVpath = filepath.split("=")[1];
  1113. updateMainPlayerUI(displayName,info,id, fileVpath);
  1114. loadAndPlayAudioFile(filepath, !startPaused);
  1115. if (!currentPlaying && !startPaused){
  1116. setPlaying(true);
  1117. }
  1118. playingFileDetail = [parseInt(id),filepath];
  1119. //If the user play this file, assume the next file to be added to playlist is this file
  1120. playlistAddPendingFile = filepath;
  1121. //Have a backup of the current list just incase the user open another directory while a list is playing
  1122. //Only backup when it is not call from dropdown list
  1123. if (!$(object).parent().hasClass("dropdownList")){
  1124. playingList = Array.from(displayList);
  1125. pagingEnableForPlayingList = pagingEnabled;
  1126. currentPlayingPage = currentPage;
  1127. }
  1128. parsePlayingSongList();
  1129. if ($("#miniPlayer").hasClass("hidden")){
  1130. //This is the first song that has played after the UI init
  1131. $("#miniPlayer").css("display","none").removeClass("hidden").slideDown();
  1132. }
  1133. showMainPlayerInterface();
  1134. //Just in case the albumn image changed, albumn art css is also updated.
  1135. resizeQuickAdjust();
  1136. updateStateReferingURL();
  1137. highLightPlayingMusic();
  1138. }
  1139. //Check if a music file thumbnail exists in cache
  1140. function getThumbnailFromCache(filepath, callback){
  1141. if (dbExists){
  1142. let dbTx = cacheDb.transaction("thumblist","readwrite");
  1143. let tstore = dbTx.objectStore("thumblist");
  1144. let retrv = tstore.get(filepath);
  1145. retrv.onsuccess = (event) => {
  1146. let cachefile = retrv.result;
  1147. if (cachefile == undefined || cachefile.content == undefined){
  1148. //thumbnail not exists in cache.
  1149. callback(undefined);
  1150. }else{
  1151. //load from cache
  1152. callback(cachefile);
  1153. }
  1154. }
  1155. }
  1156. return callback(undefined);
  1157. }
  1158. function loadThumbnailToMusicList(selector = ".mainList.file.item"){
  1159. $(selector).each(function(){
  1160. let filepath = JSON.parse(decodeURIComponent($(this).attr("filepath")));
  1161. let thisFileItemID = $(this).attr("id");
  1162. let rawname = JSON.parse(decodeURIComponent($(this).attr("rawname")));
  1163. let realVpath = filepath.split("=");
  1164. realVpath.shift();
  1165. realVpath = realVpath.join("=");
  1166. //console.log(thisFileItemID, realVpath, rawname);
  1167. getThumbnailFromCache(realVpath, function(cachedThumb){
  1168. if (cachedThumb == undefined){
  1169. //Load the thumbnail for this item in list
  1170. fetch("../system/file_system/loadThumbnail?vpath=" + encodeURIComponent(realVpath))
  1171. .then((response) => response.json())
  1172. .then((data) => {
  1173. if (data.error !== undefined || data.trim() == ""){
  1174. return;
  1175. }
  1176. $("#" + thisFileItemID).find("img").attr("src","data:image/jpg;base64," + data);
  1177. $(".dropdownList.file.item").each(function(){
  1178. var thisFilepath = JSON.parse(decodeURIComponent($(this).attr("filepath")));
  1179. if ($(this).attr("listid") == thisFileItemID && thisFilepath == filepath){
  1180. $(this).find("img").attr("src","data:image/jpg;base64," + data);
  1181. }
  1182. });
  1183. if (dbExists){
  1184. //Put this thumbnail into cache
  1185. let dbTx = cacheDb.transaction("thumblist","readwrite");
  1186. let tstore = dbTx.objectStore("thumblist");
  1187. let retrv = tstore.put({
  1188. "filename": realVpath,
  1189. "cachetime":parseInt(Date.now() / 1000),
  1190. "content": data.content,
  1191. });
  1192. }
  1193. });
  1194. }else{
  1195. //Use the result as thumbnail
  1196. console.log("Loaded from cache" , realVpath)
  1197. $("#" + thisFileItemID).find("img").attr("src","data:image/jpg;base64," + cachedThumb);
  1198. $(".dropdownList.file.item").each(function(){
  1199. var thisFilepath = JSON.parse(decodeURIComponent($(this).attr("filepath")));
  1200. if ($(this).attr("listid") == thisFileItemID && thisFilepath == filepath){
  1201. $(this).find("img").attr("src","data:image/jpg;base64," + cachedThumb);
  1202. }
  1203. });
  1204. }
  1205. });
  1206. /*
  1207. ao_module_agirun("Music/functions/getThumbnail.js", {
  1208. file: realVpath,
  1209. }, function(data){
  1210. if (data.error !== undefined){
  1211. }else{
  1212. $("#" + thisFileItemID).find("img").attr("src","data:image/jpg;base64," + data);
  1213. $(".dropdownList.file.item").each(function(){
  1214. var thisFilepath = JSON.parse(decodeURIComponent($(this).attr("filepath")));
  1215. if ($(this).attr("listid") == thisFileItemID && thisFilepath == filepath){
  1216. $(this).find("img").attr("src","data:image/jpg;base64," + data);
  1217. }
  1218. })
  1219. }
  1220. });
  1221. */
  1222. })
  1223. }
  1224. function loadThumbnail(filepath){
  1225. //Load the thumbnail
  1226. var realVpath = filepath.split("=");
  1227. realVpath.shift();
  1228. realVpath = realVpath.join("=");
  1229. playingSongVpath = realVpath;
  1230. getThumbnailFromCache(realVpath, function(thumbdata){
  1231. if (playingSongVpath != realVpath){
  1232. //Already switch to another song
  1233. return;
  1234. }
  1235. if (thumbdata == undefined){
  1236. //No thumbnail found. Load it from server
  1237. //console.log("Thumbnail cache not found", realVpath);
  1238. ao_module_agirun("Music/functions/getThumbnail.js", {
  1239. file: realVpath,
  1240. }, function(data){
  1241. if (playingSongVpath != realVpath){
  1242. //Already switch to another song
  1243. return;
  1244. }
  1245. if (data.error !== undefined){
  1246. console.log(data.error)
  1247. $("#albumnArtImage").attr("src","img/default.png");
  1248. $("#smallPlayerThumb").attr("src","img/default.png");
  1249. if (navigator.mediaSession.metadata){
  1250. navigator.mediaSession.metadata.artwork = [
  1251. { src: "img/default.png", sizes: '512x512', type: 'image/png' }
  1252. ]
  1253. }
  1254. }else{
  1255. $("#albumnArtImage").attr("src","data:image/jpg;base64," + data);
  1256. $("#smallPlayerThumb").attr("src","data:image/jpg;base64," + data);
  1257. if (isAndroid && navigator.mediaSession.metadata){
  1258. //Android
  1259. navigator.mediaSession.metadata.artwork = [
  1260. { src: "data:image/jpg;base64," + data, sizes: '480x480', type: 'image/jpg' }
  1261. ]
  1262. }
  1263. }
  1264. resizeQuickAdjust();
  1265. });
  1266. }else{
  1267. //Thumbnail found.
  1268. //console.log("Loaded song thumbnail from cache: " , realVpath);
  1269. $("#albumnArtImage").attr("src","data:image/jpg;base64," + thumbdata.content);
  1270. $("#smallPlayerThumb").attr("src","data:image/jpg;base64," + thumbdata.content);
  1271. if (isAndroid && navigator.mediaSession.metadata){
  1272. //Android
  1273. navigator.mediaSession.metadata.artwork = [
  1274. { src: "data:image/jpg;base64," + thumbdata.content, sizes: '480x480', type: 'image/jpg' }
  1275. ]
  1276. }
  1277. }
  1278. });
  1279. }
  1280. function nextSong(id = false,forcePlayEvenStopped = false){
  1281. //Check if the current playlist has more than one songs.
  1282. var currentPaused = audioElement[0].paused;
  1283. if (playingList.length > 1){
  1284. var nextSongIndex = playingFileDetail[0];
  1285. if (id != false){
  1286. //Allow manual overwrite for this function
  1287. nextSongIndex = id;
  1288. var nextSong = playingList[nextSongIndex];
  1289. }else{
  1290. if (playingFileDetail[0] >= playingList.length){
  1291. var nextSong = playingList[0]; //Back to the first song in list
  1292. nextSongIndex = 0;
  1293. }else{
  1294. var nextSong = playingList[nextSongIndex]; //Index of the playList + 1 as the index for the files is alrady i+1. (User count from one)
  1295. }
  1296. }
  1297. //The songs has to be play via background services instead of relying on DOM
  1298. var filepath = nextSong[0];
  1299. var rawname = nextSong[1];
  1300. var displayName = ao_module_codec.decodeUmFilename(rawname);
  1301. var info = nextSong[2] + " / " + nextSong[3];
  1302. var id = nextSongIndex + 1;
  1303. updateMiniPlayerUI(displayName,info,id);
  1304. //Seperate out the filepath without media server path
  1305. var fileVpath = filepath.split("=")[1];
  1306. updateMainPlayerUI(displayName,info,id, fileVpath);
  1307. if (forcePlayEvenStopped){
  1308. loadAndPlayAudioFile(filepath,true);
  1309. }else{
  1310. loadAndPlayAudioFile(filepath,!currentPaused);
  1311. }
  1312. if (currentPlaying){
  1313. setPlaying(true);
  1314. }
  1315. playingFileDetail = [id,filepath];
  1316. //Need not to update the playlist because it is the same
  1317. if (pagingEnabled){
  1318. var targetPageNumber = getPageNumberByPlaybackId(parseInt(id));
  1319. switchToPage(targetPageNumber, function(){
  1320. parsePlayingSongList();
  1321. highLightPlayingMusic();
  1322. });
  1323. }else{
  1324. highLightPlayingMusic();
  1325. }
  1326. }else{
  1327. //This is the only song in playlist. Play again from start
  1328. audioElement[0].pause();
  1329. audioElement[0].currentTime = 0;
  1330. if (!currentPaused){
  1331. audioElement[0].play();
  1332. }
  1333. }
  1334. updateStateReferingURL();
  1335. }
  1336. function previousSong(){
  1337. var currentPaused = audioElement[0].paused;
  1338. if (playingList.length > 1){
  1339. var nextSongIndex = playingFileDetail[0] - 1;
  1340. if (nextSongIndex == 0){
  1341. nextSongIndex = playingList.length;
  1342. var nextSong = playingList[nextSongIndex - 1]; //Back to the last song in list
  1343. }else{
  1344. var nextSong = playingList[playingFileDetail[0] - 2]; //Index of the playList - 1 as the index for the files is alrady i+1. (User count from one)
  1345. }
  1346. //The songs has to be play via background services instead of relying on DOM
  1347. var filepath = nextSong[0];
  1348. var rawname = nextSong[1];
  1349. var displayName = ao_module_codec.decodeUmFilename(rawname);
  1350. var info = nextSong[2] + " / " + nextSong[3];
  1351. var id = nextSongIndex;
  1352. updateMiniPlayerUI(displayName,info,id);
  1353. //Seperate out the filepath without media server path
  1354. var fileVpath = filepath.split("=")[1];
  1355. updateMainPlayerUI(displayName,info,id, fileVpath);
  1356. loadAndPlayAudioFile(filepath,!currentPaused);
  1357. if (currentPlaying){
  1358. setPlaying(true);
  1359. }
  1360. playingFileDetail = [id,filepath];
  1361. //Need not to update the playlist because it is the same
  1362. if (pagingEnabled){
  1363. var targetPageNumber = getPageNumberByPlaybackId(parseInt(id));
  1364. switchToPage(targetPageNumber, function(){
  1365. parsePlayingSongList();
  1366. highLightPlayingMusic();
  1367. });
  1368. }else{
  1369. highLightPlayingMusic();
  1370. }
  1371. }else{
  1372. //This is the only song in playlist. Play again from start
  1373. audioElement[0].pause();
  1374. audioElement[0].currentTime = 0;
  1375. audioElement[0].play();
  1376. }
  1377. updateStateReferingURL();
  1378. }
  1379. var originalVol = 0;
  1380. function togglePlayMode(){
  1381. if (currentPlaying){
  1382. originalVol = audioElement[0].volume;
  1383. fadeAudio();
  1384. setPlaying(false);
  1385. }else{
  1386. gainAudio();
  1387. setPlaying(true);
  1388. }
  1389. }
  1390. let audioTransitioning = false;
  1391. function fadeAudio(){
  1392. audioTransitioning = true;
  1393. if(audioElement[0].volume > 0){
  1394. var testval = audioElement[0].volume - 0.1;
  1395. audioElement[0].volume = Math.max(0,testval);
  1396. setTimeout(fadeAudio, 50);
  1397. }else{
  1398. audioElement[0].pause();
  1399. setTimeout(function(){
  1400. audioElement[0].volume = originalVol;
  1401. updateStateReferingURL();
  1402. audioTransitioning = false;
  1403. }, 100);
  1404. }
  1405. }
  1406. var targetVol = 0;
  1407. function gainAudio(){
  1408. targetVol = audioElement[0].volume;
  1409. audioElement[0].volume = 0;
  1410. setTimeout(function(){
  1411. audioElement[0].play();
  1412. recursiveGainAudio();
  1413. }, 100);
  1414. }
  1415. function recursiveGainAudio(){
  1416. audioTransitioning = true;
  1417. if(audioElement[0].volume < targetVol){
  1418. if (audioElement[0].volume + 0.1 < 1){
  1419. audioElement[0].volume += 0.1
  1420. }else{
  1421. //Audio volume larger than 1, make it 1
  1422. audioElement[0].volume = 1
  1423. }
  1424. setTimeout(recursiveGainAudio, 50);
  1425. }else{
  1426. setTimeout(function(){
  1427. audioElement[0].volume = targetVol;
  1428. updateStateReferingURL();
  1429. audioTransitioning = false;
  1430. }, 100);
  1431. }
  1432. }
  1433. //Update all icons on play and pause buttons
  1434. function setPlaying(playing){
  1435. if (playing == true){
  1436. $(".PlayButton").attr("class","pause icon whiteFont PlayButton");
  1437. currentPlaying = true;
  1438. }else{
  1439. $(".PlayButton").attr("class","play icon whiteFont PlayButton");
  1440. currentPlaying = false;
  1441. }
  1442. }
  1443. function isSupportedCachingAudioFormat(ext){
  1444. if (ext == "mp3" || ext == "aac" || ext == "flac"|| ext == "wav"|| ext == "ogg"){
  1445. return true;
  1446. }
  1447. return false;
  1448. }
  1449. function loadAndPlayAudioFile(sourceURL,playAfterLoad = true){
  1450. var audio = audioElement;
  1451. //These was added to fix the legacy file listing issue
  1452. var fd = sourceURL.split("=");
  1453. var rootPath = fd.shift();
  1454. var filename = fd.join("=");
  1455. var playbackURL = "../" + rootPath + "=" + encodeURIComponent(filename); //Convert absolute dir to relative
  1456. var ext = filename.split(".").pop();
  1457. playingSongVpath = filename;
  1458. if (dbExists && (!isFirefox)){
  1459. cacheDbTx = cacheDb.transaction("files","readwrite");
  1460. cacheStore = cacheDbTx.objectStore("files");
  1461. let retrvReq = cacheStore.get(filename);
  1462. retrvReq.onsuccess = (event) => {
  1463. let cachefile = retrvReq.result;
  1464. if (cachefile == undefined || cachefile.content == undefined){
  1465. //No cache. Play from streaming and cache this
  1466. $("#mainAudioPlayer").attr("src", playbackURL);
  1467. startPlaybackAfterAudioLoaded(audio, playAfterLoad);
  1468. //Only cache non video audio tracks
  1469. if (isSupportedCachingAudioFormat(ext)){
  1470. loadAudioFileURLAsBlob(playbackURL, function(fileBlob){
  1471. //Store the blob into indexDB
  1472. let cacheDbTx2 = cacheDb.transaction("files","readwrite");
  1473. let cacheStore2 = cacheDbTx2.objectStore("files");
  1474. cacheStore2.put({
  1475. "filename": filename,
  1476. "cachetime": parseInt(Date.now() / 1000),
  1477. "content": fileBlob
  1478. });
  1479. });
  1480. }
  1481. }else if (isSupportedCachingAudioFormat(ext)){
  1482. //Cache exists. Load this instead
  1483. console.log("[AirMusic] Loaded from cache ", filename)
  1484. let reader = new FileReader();
  1485. reader.onload = function(e) {
  1486. if (playingSongVpath != filename){
  1487. //Already switch to another song
  1488. return;
  1489. }
  1490. let srcUrl = e.target.result;
  1491. //Force overwrite mime type
  1492. let dx = srcUrl.split(";base64");
  1493. let ext = cachefile.filename.split(".").pop();
  1494. let mime = dx.shift();
  1495. mime = mime.split("/")
  1496. mime.pop();
  1497. mime = mime[0] + "/" + ext;
  1498. let adjustedAudioData = mime + ";base64" + dx[0];
  1499. //Put the final data into audio elements
  1500. $("#mainAudioPlayer").attr("src", adjustedAudioData);
  1501. startPlaybackAfterAudioLoaded(audio, playAfterLoad);
  1502. };
  1503. reader.readAsDataURL(cachefile.content);
  1504. }else{
  1505. //fallback
  1506. $("#mainAudioPlayer").attr("src", playbackURL);
  1507. startPlaybackAfterAudioLoaded(audio, playAfterLoad);
  1508. }
  1509. }
  1510. }else{
  1511. //IndexedDB not found
  1512. $("#mainAudioPlayer").attr("src", playbackURL);
  1513. startPlaybackAfterAudioLoaded(audio, playAfterLoad);
  1514. }
  1515. loadThumbnail(sourceURL);
  1516. }
  1517. function startPlaybackAfterAudioLoaded(audio, playAfterLoad=true){
  1518. audio[0].pause();
  1519. audio[0].load();
  1520. if(playAfterLoad){
  1521. audio[0].oncanplaythrough = audio[0].play();
  1522. }else{
  1523. var currentTime = audioElement[0].currentTime;
  1524. var duration = audioElement[0].duration;
  1525. $('#audioProgressBar').css('width','0%');
  1526. updatePlaybackDisplayTime(currentTime,duration);
  1527. }
  1528. }
  1529. function updateMiniPlayerUI(displayName, fileinfo,id){
  1530. $("#miniPlayerDisplayName").text(displayName);
  1531. $("#miniPlayerInformation").text(fileinfo);
  1532. $("#miniPlayerIDtab").text(id + "/" + totalMusicCount);
  1533. }
  1534. function updateMainPlayerUI(songname, fileinfo, id, filepath){
  1535. $("#mainPlayerSongTitle").text(songname);
  1536. $("#mainPlayerSongDesc").text(fileinfo);
  1537. $("#mainPlayerMiniTab").text(id + "/" + totalMusicCount);
  1538. if ('mediaSession' in navigator){
  1539. var infoRewrite = fileinfo.split(" / ")
  1540. updateTitle(songname, infoRewrite[1] + " (" + infoRewrite[0] + ")", id + "/" + totalMusicCount, filepath);
  1541. }
  1542. }
  1543. /*
  1544. Playlist related functions
  1545. */
  1546. function renderPlaylistByName(listname){
  1547. $("#interfaceTitle").text(listname);
  1548. ao_module_agirun("Music/functions/playlist.js", {
  1549. opr: "list",
  1550. playlistname: listname
  1551. }, function(data){
  1552. $("#mainList").html("");
  1553. if (data.error !== undefined){
  1554. //This playlist no longer exists. Back to main
  1555. loadPlaylistView();
  1556. }else{
  1557. //Updat ethe global values
  1558. displayList = data;
  1559. totalMusicCount = data.length;
  1560. currentPath = listname;
  1561. //Add the back btn for back to playlist view
  1562. $("#mainList").append(`<div class="mainList item extrapadding" onClick="loadPlaylistView();">
  1563. <div class="ui header selectable" style="margin:0px !important;">
  1564. <i class="angle left icon whiteFont" style="overflow:hidden;"></i>
  1565. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%;">
  1566. ../
  1567. </div>
  1568. </div>
  1569. </div>`);
  1570. //List the resulting song list
  1571. for (var i = 0; i < data.length; i++){
  1572. var songInfo = data[i];
  1573. $("#mainList").append(`<div class="mainList file item" filepath=${ao_module_utils.objectToAttr(songInfo[0])} id=${i+1} rawname=${ao_module_utils.objectToAttr(songInfo[1])}>
  1574. <div class="ui header selectable" style="margin:0px !important;" onClick="playSong(this);">
  1575. <img class="ui small image" src="img/eq.svg" style="margin-right: 0.2em;"></img>
  1576. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%; font-weight: lighter;">
  1577. ${songInfo[1]}
  1578. <div class="sub header fileinfo" style="color: #c7c7c7;">${songInfo[2]} / ${songInfo[3]}</div>
  1579. </div>
  1580. </div>\
  1581. <div class="topRightCorner" align="center">
  1582. ${i + 1}
  1583. </div>
  1584. <div class="mainList rightFunctionBar" type="file" align="center" onclick="showMore(this);">
  1585. <i class="ellipsis vertical icon" style="margin-top:1.2em;"></i>
  1586. </div>
  1587. </div>`);
  1588. //Update the interface Detail
  1589. $("#interfaceDetails").text("[" + data.length + " files]");
  1590. };
  1591. loadThumbnailToMusicList();
  1592. //Fix some legacy css isseus
  1593. $("#mainList").append("<br><br><br><br><br><br><br>");
  1594. }
  1595. });
  1596. }
  1597. //Open a given playlist
  1598. function openPlaylist(object){
  1599. var listname = $(object).attr("listname");
  1600. renderPlaylistByName(listname);
  1601. }
  1602. function addToNewPlaylist(){
  1603. var playlistname = prompt("Enter new playlist name");
  1604. if (playlistname != null && playlistname != ""){
  1605. //Add to playlist
  1606. addSongToPlayList(playlistname);
  1607. }else{
  1608. $("#succSnackBar").find(".content").html(`<i class="remove icon"></i> Invalid playlist name`);
  1609. $("#succSnackBar").slideDown("fast").delay(3000).slideUp("fast");
  1610. }
  1611. }
  1612. function addToPlaylistFromMoreMenu(){
  1613. $(".showMoreMenus").fadeOut('fast');
  1614. $("#showmoreUIcover").fadeOut('fast');
  1615. showPlaylistInterface();
  1616. }
  1617. //Remove the curernt file from the current playlist
  1618. function removeFromPlylistFromMoreMenu(){
  1619. if (currentMode == "playlist"){
  1620. //Remvoe the playlistAddPendingFile
  1621. //In playlist mode, the currentPath is used to store the plylist name
  1622. ao_module_agirun("Music/functions/playlist.js", {
  1623. opr: "remove",
  1624. playlistname: currentPath,
  1625. musicpath: playlistAddPendingFile.replace("/media?file=","")
  1626. }, function(data){
  1627. if (data.error !== undefined){
  1628. alert(data.error);
  1629. }else{
  1630. //Removed. Reload playlist
  1631. renderPlaylistByName(currentPath);
  1632. //Hide the MoreMenu
  1633. hideShowMoreMenu();
  1634. }
  1635. });
  1636. }
  1637. }
  1638. function addSongToSelectedPlaylist(object){
  1639. var playlistName = $(object).attr("name").trim();
  1640. addSongToPlayList(playlistName);
  1641. }
  1642. function addSongToPlayList(listname){
  1643. //Get current music file name
  1644. var currentSongPath = "";
  1645. if (playlistAddPendingFile !== ""){
  1646. currentSongPath = playlistAddPendingFile.replace("/media?file=","");
  1647. }else{
  1648. $("#succSnackBar").find(".content").html(`<i class="remove icon"></i> No song selected`);
  1649. $("#succSnackBar").slideDown("fast").delay(3000).slideUp("fast");
  1650. return;
  1651. }
  1652. //Add to playlist
  1653. ao_module_agirun("Music/functions/playlist.js", {
  1654. opr: "add",
  1655. playlistname: listname,
  1656. musicpath: currentSongPath
  1657. },function(data){
  1658. //Show success
  1659. $("#succSnackBar").find(".content").html(`<i class="checkmark icon"></i> Added to playlist ${listname}`);
  1660. $("#succSnackBar").slideDown("fast").delay(3000).slideUp("fast");
  1661. //Reload the playlist
  1662. initPlaylistInterfaceList();
  1663. });
  1664. }
  1665. //List the number of playlist stored in this database
  1666. function loadPlaylistView(){
  1667. currentMode = "playlist";
  1668. //Clear the main list
  1669. $("#mainList").html("");
  1670. togglePagingMode(false);
  1671. ao_module_agirun("Music/functions/playlist.js", {
  1672. opr: "root",
  1673. },function(data){
  1674. //Get the list of playlist
  1675. //console.log(data);
  1676. //Render the elements
  1677. data.forEach(playlist => {
  1678. $("#mainList").append(`<div class="mainList item" listname="${playlist.name}" tag="playlist" onClick="openPlaylist(this);">
  1679. <div class="ui header selectable" style="margin:0px !important;" >
  1680. <img class="ui small image" src="img/list.svg" style="margin-right: 0.2em;"></img>
  1681. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%;">
  1682. ${playlist.name}
  1683. <div class="sub header fileinfo" style="color: #c7c7c7;">[${playlist.count} files]</div>
  1684. </div>
  1685. </div>
  1686. <div class="mainList rightFunctionBar" tag="moreInfo" align="center" onClick="openPlaylist(this);">
  1687. <i class="chevron right icon" style="margin-top:1.2em;"></i>
  1688. </div>
  1689. </div>`);
  1690. });
  1691. hideLeftMenu();
  1692. //Update the headers
  1693. $("#interfaceTitle").text("Playlist");
  1694. $("#AMmenuIcon").attr("class","list icon large whiteFont");
  1695. $("#interfaceDetails").text("[" + data.length + " playlist]");
  1696. });
  1697. }
  1698. function loadFolderView(){
  1699. currentMode = "folder";
  1700. currentPath = "";
  1701. var tempalte = '<div class="mainList item" filepath={filepath} id={id} tag="folder" onClick="openFolder(this);">\
  1702. <div class="ui header selectable" style="margin:0px !important;" >\
  1703. <img class="ui small image" src="img/fo.svg" style="margin-right: 0.2em;"></img>\
  1704. <div class="content whiteFont" style="padding-top: 2px; line-height:1em;width : 80%; font-weight: lighter;">\
  1705. {foldername}\
  1706. <div class="sub header fileinfo" style="color: #c7c7c7;">{fileinfo}</div>\
  1707. </div>\
  1708. </div>\
  1709. <div class="mainList rightFunctionBar" tag="moreInfo" align="center" onClick="moreFolder(this);">\
  1710. <i class="chevron right icon" style="margin-top:1.2em;"></i>\
  1711. </div>\
  1712. </div>';
  1713. $("#interfaceTitle").text("Storage");
  1714. togglePagingMode(false);
  1715. $("#AMmenuIcon").attr("class","folder open icon large whiteFont");
  1716. ao_module_agirun("Music/functions/listSong.js", {
  1717. listdir: "root",
  1718. },function(data){
  1719. $("#mainList").html("");
  1720. for (var i =0; i < data.length; i++){
  1721. var folderName = data[i][0];
  1722. var folderPath = data[i][1];
  1723. var fileCount = data[i][2];
  1724. var folderCount = data[i][3];
  1725. var box = tempalte;
  1726. box = replaceAll("{filepath}",folderPath,box);
  1727. box = replaceAll("{id}",i + 1,box);
  1728. if (folderName == ".cache" || folderName == ".trash"){
  1729. //Hidden folders
  1730. continue;
  1731. }
  1732. if (folderPath.includes("/media")){
  1733. //This is from external storage devices. List its number as well.
  1734. var tmp = folderPath.split("/");
  1735. var extStoragePath = "/" + tmp[1] + "/" + tmp[2];
  1736. box = replaceAll("{foldername}",folderName + " ( " + extStoragePath + " )",box);
  1737. }else{
  1738. //This is directory inside normal folders.
  1739. box = replaceAll("{foldername}",folderName,box);
  1740. }
  1741. /*
  1742. var fileinfo = fileinfo = "[No playable files]";
  1743. console.log(folderCount, fileCount);
  1744. if (folderCount > 0 && fileCount > 0){
  1745. fileinfo = "[" + fileCount + " files, " + folderCount +" folders]"
  1746. }else if (fileCount > 0){
  1747. fileinfo = "[" + fileCount + " files]";
  1748. }else if (fileCount == -1 && folderCount == -1){
  1749. fileinfo = "";
  1750. }
  1751. */
  1752. var fileinfo = folderPath;
  1753. box = replaceAll("{fileinfo}",fileinfo,box);
  1754. rootPaths.push(folderPath);
  1755. $("#mainList").append(box);
  1756. }
  1757. $("#interfaceDetails").text("[" + data.length + " folders]");
  1758. });
  1759. hideLeftMenu();
  1760. }
  1761. function isMobile(){
  1762. if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
  1763. return true
  1764. }
  1765. return false
  1766. }
  1767. function setWindowHash(hashValue){
  1768. hashValue = JSON.stringify(hashValue);
  1769. if (!isAndroid){
  1770. return;
  1771. }
  1772. if(history.pushState) {
  1773. window.history.pushState(null, null, '#' + hashValue);
  1774. }else {
  1775. location.hash = '#' + hashValue;
  1776. }
  1777. if(ao_module_virtualDesktop && !isMobile()){
  1778. //Update the iframe src as well
  1779. var newsrc = window.frameElement.getAttribute("src");
  1780. if (newsrc.includes("#")){
  1781. newsrc = newsrc.split("#")
  1782. newsrc.pop();
  1783. newsrc = newsrc.join("#");
  1784. }
  1785. newsrc = newsrc + "#" + hashValue;
  1786. $(window.frameElement).attr("src",newsrc);
  1787. //console.log(window.frameElement.getAttribute("src"));
  1788. }
  1789. }
  1790. function updateStateReferingURL(){
  1791. var paused = audioElement[0].paused; //Check the current playing state of the player
  1792. setWindowHash({path: currentPath, pfp:playingFileDetail,pause:paused});
  1793. }
  1794. function openFolder(object, playParameters=null){
  1795. var playIDAfterOpen = -1;
  1796. var startPaused = false;
  1797. if (playParameters !== null){
  1798. playIDAfterOpen = playParameters.playIDAfterOpen;
  1799. startPaused = playParameters.startPaused;
  1800. }
  1801. var backbtnTemplate = '<div class="mainList item extrapadding" filepath={filepath} id={id} onClick="openFolder(this);">\
  1802. <div class="ui header selectable" style="margin:0px !important;">\
  1803. <i class="angle left icon whiteFont" style="overflow:hidden;"></i>\
  1804. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%; font-weight: lighter;">\
  1805. ../\
  1806. </div>\
  1807. </div>\
  1808. </div>';
  1809. var folderTemplate = '<div class="mainList item" filepath={filepath} tag="folder" id={id} onClick="openFolder(this);">\
  1810. <div class="ui header selectable" style="margin:0px !important;">\
  1811. <img class="ui small image" src="img/fo.svg" style="margin-right: 0.2em;"></img>\
  1812. <div class="content whiteFont" style="padding-top:2px;line-height:1em; width:80%; font-weight: lighter;">\
  1813. {foldername}\
  1814. <div class="sub header fileinfo" style="color: #c7c7c7;">{fileinfo}</div>\
  1815. </div>\
  1816. </div>\
  1817. <div class="mainList rightFunctionBar" type="folder" align="center">\
  1818. <i class="chevron right icon" style="margin-top:1.2em;"></i>\
  1819. </div>\
  1820. </div>';
  1821. var fileTemplate = `<div class="mainList file item" filepath={filepath} id={id} rawname={rawname}>\
  1822. <div class="ui header selectable" style="margin:0px !important;" onClick="playSong(this);">\
  1823. <img class="ui small image" src="img/eq.svg" style="margin-right: 0.2em;"></img>
  1824. <!-- <i class="music icon whiteFont" style="overflow:hidden;"></i> -->\
  1825. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%; font-weight: lighter;">\
  1826. {songtitle}\
  1827. <div class="sub header fileinfo" style="color: #c7c7c7;">{ext} / {size}</div>\
  1828. </div>\
  1829. </div>\
  1830. <div class="topRightCorner" align="center">\
  1831. {id}\
  1832. </div>\
  1833. <div class="mainList rightFunctionBar" type="file" align="center">\
  1834. <i class="ellipsis vertical icon" style="margin-top:1.2em;"></i>\
  1835. </div>\
  1836. </div>`;
  1837. var targetPath = decodeURIComponent($(object).attr("filepath"));
  1838. if (targetPath == "root" || targetPath == "/"){
  1839. //User request to go back to storage root
  1840. loadFolderView();
  1841. return;
  1842. }
  1843. currentPath = targetPath.split("/./").join("/");
  1844. currentPath = currentPath.split("//").join("/");
  1845. $("#interfaceTitle").text(ao_module_codec.decodeHexFoldername(targetPath.substring(0,targetPath.length -1).split("/").pop()));
  1846. var parentDir = currentPath.split("/");
  1847. parentDir.pop();parentDir.pop();
  1848. parentDir = (parentDir.join("/") + "/");
  1849. //console.log(currentPath);
  1850. var backbtn;
  1851. if (rootPaths.includes(currentPath) == false){
  1852. //We are currently not at root
  1853. backbtn = backbtnTemplate;
  1854. backbtn = replaceAll("{filepath}",encodeURIComponent(parentDir),backbtn);
  1855. backbtn = replaceAll("{id}",0,backbtn);
  1856. }else{
  1857. //Create a back button to go back to root of storage
  1858. backbtn = backbtnTemplate;
  1859. backbtn = replaceAll("{filepath}","root",backbtn);
  1860. backbtn = replaceAll("{id}",0,backbtn);
  1861. }
  1862. //Request the server for a list of folders and file in this directory
  1863. ao_module_agirun("Music/functions/listSong.js", {
  1864. listdir: targetPath.split("//").join("/"),
  1865. },function(data){
  1866. $("#mainList").html("");
  1867. $("#mainList").append(backbtn);
  1868. if (Array.isArray(data)){
  1869. var folders = data[0];
  1870. var files = data[1];
  1871. //List all folders
  1872. for (var i =0; i < folders.length; i++){
  1873. var folderName = folders[i][0];
  1874. var folderPath = folders[i][1];
  1875. var fileCount = folders[i][2];
  1876. var folderCount = folders[i][3];
  1877. var box = folderTemplate;
  1878. if (folderName == ".cache" || folderName == ".trash"){
  1879. //Hidden folders
  1880. continue;
  1881. }
  1882. box = replaceAll("{filepath}",encodeURIComponent(folderPath),box);
  1883. box = replaceAll("{id}","folder-" + i + 1,box);
  1884. box = replaceAll("{foldername}",ao_module_codec.decodeHexFoldername(folderName),box);
  1885. var fileinfo = "[" + fileCount + " files]"
  1886. if (folderCount > 0){
  1887. fileinfo = "[" + fileCount + " files, " + folderCount +" folders]"
  1888. }else if (folderCount == -1){
  1889. fileinfo = folderPath;
  1890. }
  1891. box = replaceAll("{fileinfo}",fileinfo,box);
  1892. $("#mainList").append(box);
  1893. }
  1894. //List all files
  1895. for ( var i =0; i < files.length; i++){
  1896. var songInfo = files[i];
  1897. var path = songInfo[0];
  1898. var displayname = ao_module_codec.decodeUmFilename(songInfo[1]);
  1899. var ext = songInfo[2];
  1900. var size = songInfo[3];
  1901. var box = fileTemplate;
  1902. box = replaceAll("{filepath}",ao_module_utils.objectToAttr(path),box);
  1903. box = replaceAll("{id}",i + 1,box); //User count from 1
  1904. box = replaceAll("{rawname}",ao_module_utils.objectToAttr(songInfo[1]),box);
  1905. box = replaceAll("{songtitle}",displayname,box);
  1906. box = replaceAll("{ext}",ext,box);
  1907. box = replaceAll("{size}",size,box);
  1908. $("#mainList").append(box);
  1909. }
  1910. displayList = files;
  1911. totalMusicCount = files.length;
  1912. $("#mainList").append("<br><br><br><br><br><br><br>");
  1913. }else{
  1914. //Something went wrong
  1915. //console.log('[AirMusic] Something went wrong: ' + data);
  1916. loadFolderView();
  1917. return;
  1918. }
  1919. if (folders.length > 0 && files.length > 0){
  1920. $("#interfaceDetails").text("[" + files.length + " files, " + folders.length+ " folders]");
  1921. }else if (folders.length > 0){
  1922. $("#interfaceDetails").text("[" + folders.length + " folders]");
  1923. }else if (files.length > 0){
  1924. $("#interfaceDetails").text("[" + files.length + " files]");
  1925. }else{
  1926. $("#interfaceDetails").text("[0 files or folders]");
  1927. }
  1928. //Hook all the events for the moreinfo on folders
  1929. hookMoreFolderInfoClickEvent();
  1930. //Check if the current playing file is located inside this list.
  1931. highLightPlayingMusic();
  1932. //Check if auto playback is required. If yes, play it with the given filepath.
  1933. if (playIDAfterOpen != -1){
  1934. $(".mainList.item").each(function(){
  1935. if ($(this).attr("id") == playIDAfterOpen){
  1936. //This is the file that require to playback after the folder loaded
  1937. playSong($(this).find(".ts.header.selectable"),startPaused);
  1938. setTimeout(resizeQuickAdjust,500);
  1939. }
  1940. });
  1941. }
  1942. //Load thumbnail for song in list
  1943. loadThumbnailToMusicList();
  1944. });
  1945. }
  1946. function moreInfo(object){
  1947. if ($(object).parent().attr('tag') == "folder"){
  1948. //This is a folder. Ask if play as playlist
  1949. alert("Folder playback work in progress");
  1950. }else{
  1951. showMore(object);
  1952. }
  1953. }
  1954. function hookMoreFolderInfoClickEvent(){
  1955. $(".mainList.rightFunctionBar").on("click", function(e){
  1956. e.stopPropagation();
  1957. moreInfo(this);
  1958. });
  1959. }
  1960. function highLightPlayingMusic(){
  1961. //This function is used for highlighting the current playing music if the music piece is found inside the current list
  1962. $(".mainList.item").removeClass("playingTrack");
  1963. $(".mainList.item").each(function(){
  1964. var id = parseInt($(this).attr("id"));
  1965. try{
  1966. var filepath = ao_module_utils.attrToObject($(this).attr("filepath"));
  1967. }catch{
  1968. //Use back the previous method of filepath storage for compatibility
  1969. var filepath = $(this).attr("filepath");
  1970. }
  1971. //Id is ignored in the 9/9/2019 updates and only check if the path matches.
  1972. if (filepath == playingFileDetail[1]){
  1973. $(this).addClass("playingTrack");
  1974. }
  1975. //console.log([id,filepath], playingFileDetail);
  1976. });
  1977. //Update dropdownList as well if exists
  1978. $(".dropdownList.item").removeClass("playingTrack");
  1979. $(".dropdownList.item").each(function(){
  1980. try{
  1981. var filepath = ao_module_utils.attrToObject($(this).attr("filepath"));
  1982. }catch{
  1983. //Use back the previous method of filepath storage for compatibility
  1984. var filepath = $(this).attr("filepath");
  1985. }
  1986. //var filepath = $(this).attr("filepath");
  1987. if (filepath == playingFileDetail[1]){
  1988. $(this).addClass("playingTrack");
  1989. }
  1990. });
  1991. }
  1992. function hideShowMoreMenu(){
  1993. $(".showMoreMenus").fadeOut('fast');
  1994. $("#showmoreUIcover").fadeOut('fast');
  1995. //Return the playlistAddPendingFile object back to the playing one
  1996. if (playingFileDetail !== undefined){
  1997. playlistAddPendingFile = playingFileDetail[1];
  1998. }else{
  1999. //No song is being play back
  2000. playlistAddPendingFile = "";
  2001. }
  2002. }
  2003. function playFromShowMoreMenu(){
  2004. nextSong(showMoreOprPlayID - 1);
  2005. $(".showMoreMenus").fadeOut('fast');
  2006. }
  2007. function showFileInfo(){
  2008. $("#showFileInfo").show();
  2009. $("#showMoreUI").hide();
  2010. }
  2011. function startRelatedSearch(){
  2012. enterSearchMode();
  2013. $("#searchInputBar").val(showMoreoprDisplayName);
  2014. $("#searchInputBar").focus();
  2015. hideShowMoreMenu();
  2016. }
  2017. function searchYoutubeViaShowMore(){
  2018. if (showMoreoprDisplayName != "" || showMoreoprDisplayName != undefined){
  2019. var filename = showMoreoprDisplayName;
  2020. searchOnYoutube(filename);
  2021. }
  2022. }
  2023. var showMoreOprPlayID,showMoreOprFilepath, showMoreoprDisplayName;
  2024. function showMore(object){
  2025. var filepath = $(object).parent().attr("filepath");
  2026. filepath = JSON.parse(decodeURIComponent(filepath));
  2027. //User want more action on this file. assume this is the file to add
  2028. playlistAddPendingFile = filepath;
  2029. var id = $(object).parent().attr('id');
  2030. var rawname = $(object).parent().attr("rawname");
  2031. var displayName = JSON.parse(decodeURIComponent(ao_module_codec.decodeUmFilename(rawname)));
  2032. //Update global variable for quick operations
  2033. showMoreOprPlayID = id;
  2034. showMoreOprFilepath = filepath;
  2035. showMoreoprDisplayName = displayName;
  2036. $("#showMoreUI").find(".songTitle").text(displayName);
  2037. $("#showMoreUI").find(".songID").text(id);
  2038. $("#showFileInfo").find(".songTitle").text(displayName);
  2039. $("#showMoreUI").fadeIn('fast');
  2040. $("#showmoreUIcover").fadeIn('fast');
  2041. //Update fileinformation as well
  2042. if (filepath.substring(0, 12) == "/media?file="){
  2043. filepath = filepath.substring(12);
  2044. }
  2045. //Pre-render the file info
  2046. ao_module_agirun("Music/functions/getFileInfo.js", {
  2047. filepath: filepath,
  2048. }, function(data){
  2049. $("#showFileInfo").find(".filename").text(ao_module_codec.decodeUmFilename(data[0]));
  2050. $("#showFileInfo").find(".rawname").text(data[0]);
  2051. $("#showFileInfo").find(".filepath").text(data[1]);
  2052. $("#showFileInfo").find(".filesize").text(data[2] + " (" + data[3] + " Bytes)");
  2053. $("#showFileInfo").find(".filedate").text(data[4]);
  2054. });
  2055. if (currentMode != "playlist"){
  2056. $(".playlistonly").hide();
  2057. }else{
  2058. $(".playlistonly").show();
  2059. }
  2060. }
  2061. function playSongFromDropdownList(object){
  2062. //Play song from dropdown list. Hence, no need to update dropdownList
  2063. if ($(object).parent().hasClass("playingTrack")){
  2064. //This song already playing. Ignore play request.
  2065. return;
  2066. }
  2067. if (pagingEnableForPlayingList && $(object).attr("targetPage") != currentPlayingPage){
  2068. let newPage = parseInt($(object).attr("targetPage"));
  2069. if (!isNaN(newPage)){
  2070. currentPlayingPage = newPage;
  2071. }
  2072. }
  2073. playSong(object);
  2074. //Check if the song is also in main list. If yes, highlight it as well
  2075. /*
  2076. $(".mainList.item").each(function(){
  2077. if ($(this).attr("filepath") == $(object).parent().attr("filepath")){
  2078. $(".mainList.item.playingTrack").removeClass("playingTrack");
  2079. $(this).addClass("playingTrack");
  2080. }
  2081. });
  2082. */
  2083. $("#dropdownSonglist").delay(500).slideUp();
  2084. highLightPlayingMusic();
  2085. }
  2086. //Move the playing song list into the dropdown song list. This list might not be the same as the one in the main list.
  2087. function parsePlayingSongList(){
  2088. $("#currentPlayingMainList").html("");
  2089. var counter = playingList.length;
  2090. var totalSize = 0.0;
  2091. var renderRange = [0, playingList.length];
  2092. var pageKeepRange = [0, playingList.length]
  2093. if (pagingEnableForPlayingList){
  2094. //Paging Enabled. Only show 1/2 max + current page song + 1/2 max
  2095. var startEndRange = getPageStartAndEndByPageNumber(currentPlayingPage, playingList);
  2096. startEndRange = [startEndRange[0] - pagingCutoffCount /2, startEndRange[1] + pagingCutoffCount / 2]
  2097. //console.log("DEFAULT START END RANGE", startEndRange)
  2098. //page keep range is the middle 1/2 number of songs, [1/4 => prev page][1/2][1/4 => next page]
  2099. pageKeepRange[0] = startEndRange[0] + pagingCutoffCount / 2;
  2100. pageKeepRange[1] = startEndRange[1] - pagingCutoffCount / 2;
  2101. if (startEndRange[0] < 0){
  2102. startEndRange[0] = 0;
  2103. }
  2104. if (startEndRange[1] > playingList.length){
  2105. startEndRange[1] = playingList.length;
  2106. }
  2107. renderRange = startEndRange;
  2108. if (pageKeepRange[0] < 0){
  2109. pageKeepRange[0] = 0;
  2110. }
  2111. if (pageKeepRange[1] > playingList.length){
  2112. pageKeepRange[1] = playingList.length;
  2113. }
  2114. //console.log("KEEP RANGE", pageKeepRange);
  2115. }
  2116. for (var i = renderRange[0]; i < renderRange[1]; i++){
  2117. var displayname = ao_module_codec.decodeUmFilename(playingList[i][1]);
  2118. if (playingList[i][3].includes("MB")){
  2119. totalSize += parseFloat(playingList[i][3].split(" ")[0]);
  2120. }else if (playingList[i][3].includes("KB")){
  2121. totalSize += parseFloat(playingList[i][3].split(" ")[0]) / 1000;
  2122. }else if (playingList[i][3].includes("GB")){
  2123. totalSize += parseFloat(playingList[i][3].split(" ")[0]) * 1000;
  2124. }
  2125. //Get thumbnail from the current list to prevent re-loading form remote
  2126. let targetThumbnail = $("#" + (i + 1)).find("img").attr("src");
  2127. let opacityShowing = "";
  2128. let realVpath = playingList[i][0].split("=");
  2129. realVpath.shift();
  2130. realVpath = realVpath.join("=");
  2131. if ($("#" + (i + 1)).length == 0 && displayList.length == playingList.length){
  2132. //Item not exists
  2133. targetThumbnail = "img/eq.svg";
  2134. opacityShowing = "opacity: 0.6;"
  2135. }else if (pagingEnableForPlayingList){
  2136. if (i < pageKeepRange[0] || i > pageKeepRange[1]){
  2137. //Out of paging range. Do hidden display
  2138. targetThumbnail = "img/eq.svg";
  2139. opacityShowing = "opacity: 0.6;"
  2140. }else{
  2141. targetThumbnail = `../system/file_system/loadThumbnail?bytes=true&vpath=${encodeURIComponent(realVpath)}`;
  2142. }
  2143. }else{
  2144. //Non paging list. Always do all thumbnails.
  2145. targetThumbnail = `../system/file_system/loadThumbnail?bytes=true&vpath=${encodeURIComponent(realVpath)}`;
  2146. }
  2147. let targetPage = currentPlayingPage;
  2148. if (i < pageKeepRange[0]){
  2149. targetPage -= 1;
  2150. }
  2151. if (i > pageKeepRange[1]){
  2152. targetPage += 1;
  2153. }
  2154. $("#currentPlayingMainList").append(`<div class="dropdownList file item" style="${opacityShowing}" filepath="${ao_module_utils.objectToAttr(playingList[i][0])}" listid="${i + 1}" rawname="${ao_module_utils.objectToAttr(playingList[i][1])}">
  2155. <div class="ui header selectable" style="margin:0px !important;" onClick="playSongFromDropdownList(this);" targetPage="${targetPage}">
  2156. <img class="ui small image" src="${targetThumbnail}" onError="replaceImageToDefault(this);" style="margin-right: 0.2em;"></img>
  2157. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%;">
  2158. <span style="font-weight: lighter;">${displayname}</span>
  2159. <div class="sub header fileinfo" style="color: #c7c7c7;">${playingList[i][2]} / ${playingList[i][3]}</div>
  2160. </div>
  2161. </div>
  2162. <div class="topRightCorner" align="center">
  2163. ${i + 1}
  2164. </div>
  2165. </div>`);
  2166. $("#dropdownListSongCount").text(counter);
  2167. $("#dropdownListIDCount").text(parseInt(totalSize) + "");
  2168. }
  2169. $(".dropdownList.item").each(function(){
  2170. if ($(this).attr('filepath') == playingFileDetail[1]){
  2171. $(this).addClass("playingTrack");
  2172. }
  2173. });
  2174. }
  2175. function loadAudioFileURLAsBlob(url, callback){
  2176. var xhr = new XMLHttpRequest();
  2177. xhr.open('GET', url);
  2178. xhr.responseType = 'blob';
  2179. xhr.onload = function(e){
  2180. //console.log("Buffer completed: ", url);
  2181. callback(xhr.response);
  2182. }
  2183. xhr.send();
  2184. }
  2185. //Clear all cached audio files
  2186. function clearAllCache(){
  2187. let dbtx = cacheDb.transaction("files","readwrite");
  2188. let fstore = dbtx.objectStore("files");
  2189. var clearReq = fstore.clear();
  2190. clearReq.onsuccess = function(e){
  2191. console.log("All cache file cleared");
  2192. }
  2193. }
  2194. function removeCacheByFilename(filename, callback=undefined){
  2195. let dbtx = cacheDb.transaction("files","readwrite");
  2196. let fstore = dbtx.objectStore("files");
  2197. let resp = fstore.delete(filename);
  2198. resp.onsuccess = function(evt){
  2199. if (callback != undefined){
  2200. callback(evt);
  2201. }
  2202. }
  2203. }
  2204. //Clear all expired cache
  2205. function clearExpiredCache(){
  2206. var expireTime = 604800; //1 week
  2207. getAllFileCache(function(allCachedTracks){
  2208. var expiredFilenames = [];
  2209. //Check all the cache to see which is expired
  2210. allCachedTracks.forEach(function(track){
  2211. if (track.cachetime + expireTime < Date.now()/1000){
  2212. //Expired. Clear this cache
  2213. expiredFilenames.push(track.filename);
  2214. console.log("[AirMusic] Expired track cleared: ", track);
  2215. }
  2216. });
  2217. //Delete those cache that have expired
  2218. expiredFilenames.forEach(function(filenameToBeDeleted){
  2219. removeCacheByFilename(filenameToBeDeleted);
  2220. });
  2221. console.log("[AirMusic] File cache clearning cycle completed");
  2222. });
  2223. getAllFileCache(function(allCachedTracks){
  2224. var expiredFilenames = [];
  2225. //Check all the cache to see which is expired
  2226. allCachedTracks.forEach(function(track){
  2227. if (track.cachetime + expireTime < Date.now()/1000){
  2228. //Expired. Clear this cache
  2229. expiredFilenames.push(track.filename);
  2230. console.log("Expired track cleared: ", track);
  2231. }
  2232. });
  2233. //Delete those cache that have expired
  2234. expiredFilenames.forEach(function(filenameToBeDeleted){
  2235. removeCacheByFilename(filenameToBeDeleted);
  2236. });
  2237. console.log("[AirMusic] Thumbnail cache clearning cycle completed")
  2238. });
  2239. }
  2240. function getAllFileCache(callback) {
  2241. var trans = cacheDb.transaction("files", IDBTransaction.READ_ONLY);
  2242. var store = trans.objectStore("files");
  2243. var items = [];
  2244. trans.oncomplete = function(evt) {
  2245. callback(items);
  2246. };
  2247. var cursorRequest = store.openCursor();
  2248. cursorRequest.onerror = function(error) {
  2249. console.log(error);
  2250. };
  2251. cursorRequest.onsuccess = function(evt) {
  2252. var cursor = evt.target.result;
  2253. if (cursor) {
  2254. items.push(cursor.value);
  2255. cursor.continue();
  2256. }
  2257. };
  2258. }
  2259. function getAllThumbCache(callback) {
  2260. var trans = cacheDb.transaction("thumblist", IDBTransaction.READ_ONLY);
  2261. var store = trans.objectStore("thumblist");
  2262. var items = [];
  2263. trans.oncomplete = function(evt) {
  2264. callback(items);
  2265. };
  2266. var cursorRequest = store.openCursor();
  2267. cursorRequest.onerror = function(error) {
  2268. console.log(error);
  2269. };
  2270. cursorRequest.onsuccess = function(evt) {
  2271. var cursor = evt.target.result;
  2272. if (cursor) {
  2273. items.push(cursor.value);
  2274. cursor.continue();
  2275. }
  2276. };
  2277. }
  2278. function replaceImageToDefault(target){
  2279. $(target).attr('src', "img/eq.svg");
  2280. }
  2281. function loadSongList(type = "all"){
  2282. currentPath = "";
  2283. currentMode = "music";
  2284. $("#interfaceTitle").text("Music");
  2285. $("#AMmenuIcon").attr("class","music icon large whiteFont")
  2286. ao_module_agirun("Music/functions/listSong.js", {
  2287. listSong: type,
  2288. },function(data){
  2289. //Initialize the song list
  2290. displayList = data;
  2291. if (type == "all"){
  2292. //Caching is used in here
  2293. displayList = data.list;
  2294. if (data.cached == true){
  2295. //This is a cached version of the music list.
  2296. console.log("Updating cached song list");
  2297. ao_module_agirun("Music/functions/buildCache.js", {}, function(data){
  2298. console.log("Cache updated: ", data);
  2299. });
  2300. }
  2301. }
  2302. //Updates 2022-07-12: Check if the list is too long. If yes, use paging
  2303. let renderRange = [0,displayList.length];
  2304. if (displayList.length > pagingCutoffCount){
  2305. togglePagingMode(true);
  2306. renderRange = [0, pagingCutoffCount];
  2307. }else{
  2308. togglePagingMode(false);
  2309. }
  2310. if (playingList == []){
  2311. playingList = Array.from(displayList);
  2312. pagingEnableForPlayingList = pagingEnabled;
  2313. currentPlayingPage = currentPage;
  2314. }
  2315. renderDisplayList(displayList,renderRange[0], renderRange[1] );
  2316. }, function(){
  2317. alert("Failed to access listSong API with type: " + type)
  2318. });
  2319. hideLeftMenu();
  2320. }
  2321. function renderDisplayList(displayList, start, end, callback=undefined){
  2322. $("#mainList").html("");
  2323. for ( var i =start; i < end; i++){
  2324. var songInfo = displayList[i];
  2325. var path = songInfo[0];
  2326. var displayname = ao_module_codec.decodeUmFilename(songInfo[1]);
  2327. var ext = songInfo[2];
  2328. var size = songInfo[3];
  2329. $("#mainList").append(`<div class="mainList file item" filepath="${ao_module_utils.objectToAttr(path)}" id="${i + 1}" rawname="${ao_module_utils.objectToAttr(songInfo[1])}">
  2330. <div class="ui header selectable" style="margin:0px !important;" onClick="playSong(this);">
  2331. <img class="ui small image" src="img/eq.svg" style="margin-right: 0.2em;"></img>
  2332. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%; font-weight: lighter;">
  2333. ${displayname}
  2334. <div class="sub header fileinfo" style="color: #c7c7c7;">${ext} / ${size}</div>
  2335. </div>
  2336. </div>
  2337. <div class="topRightCorner" align="center">
  2338. ${i + 1}
  2339. </div>
  2340. <div class="mainList rightFunctionBar" align="center" onClick="showMore(this);">
  2341. <i class="ellipsis vertical icon" style="margin-top:1.2em;"></i>\
  2342. </div>
  2343. </div>`);
  2344. }
  2345. if (pagingEnabled){
  2346. //Append the page switch buttons
  2347. let numberOfPages = Math.ceil(parseFloat(displayList.length) / parseFloat(pagingCutoffCount));
  2348. let pageSelector = ``;
  2349. for (var i = 0; i < numberOfPages; i++){
  2350. let disabled = "";
  2351. if (i == currentPage){
  2352. disabled = "disabled";
  2353. }
  2354. pageSelector = pageSelector + `<button id="pagebtn_${i}" onclick="switchToPage(${i});" class="pagebtn noborderbtn inverted basic ui icon button ${disabled}" style="box-shadow: none !important; -webkit-box-shadow: none !important;">
  2355. ${i + 1}
  2356. </button>`;
  2357. }
  2358. $("#mainList").append(`<div class="mainList item" style="cursor: unset;">
  2359. <div>${pageSelector}</div>
  2360. </div>`);
  2361. }
  2362. totalMusicCount = displayList.length;
  2363. $("#mainList").append("<br><br><br><br><br><br><br>");
  2364. $("#interfaceDetails").text("[" + totalMusicCount + " songs]");
  2365. highLightPlayingMusic();
  2366. //Load thumbnail for song in list
  2367. loadThumbnailToMusicList();
  2368. if (callback != undefined){
  2369. callback();
  2370. }
  2371. }
  2372. function switchToPage(pageNumber, callback=undefined){
  2373. if (!pagingEnabled){
  2374. return;
  2375. }
  2376. let thisCallback = callback;
  2377. if (pageNumber == currentPage){
  2378. //Already in that page
  2379. if (thisCallback != undefined){
  2380. callback();
  2381. }
  2382. return;
  2383. }
  2384. currentPage = pageNumber;
  2385. let startPage = pageNumber * pagingCutoffCount;
  2386. let endPage = startPage + pagingCutoffCount;
  2387. if (endPage > displayList.length){
  2388. endPage = displayList.length;
  2389. }
  2390. if (thisCallback == undefined){
  2391. renderDisplayList(displayList, startPage, endPage, function(){
  2392. window.scrollTo(0, document.body.scrollHeight);
  2393. });
  2394. }else{
  2395. renderDisplayList(displayList, startPage, endPage,thisCallback);
  2396. }
  2397. }
  2398. function getPageNumberByPlaybackId(id){
  2399. let numberOfPages = Math.ceil(parseFloat(displayList.length) / parseFloat(pagingCutoffCount));
  2400. let targetPageNo = Math.ceil(id / pagingCutoffCount) - 1;
  2401. return targetPageNo;
  2402. }
  2403. function getPageStartAndEndByPageNumber(pageNumber, targetList){
  2404. let startPage = pageNumber * pagingCutoffCount;
  2405. let endPage = startPage + pagingCutoffCount;
  2406. if (endPage > targetList.length){
  2407. endPage = targetList.length;
  2408. }
  2409. return [startPage, endPage];
  2410. }
  2411. function toggleLeftMenu(){
  2412. if (leftMenuShown){
  2413. $("#leftSideBar").animate({left: $("#leftSideBar").width() * -1}, 120,function(){
  2414. $("#leftSideBar").hide();
  2415. });
  2416. $("#sideBarCover").fadeOut();
  2417. leftMenuShown = false;
  2418. }else{
  2419. $("#leftSideBar").show();
  2420. $("#leftSideBar").animate({left:0}, 300);
  2421. $("#sideBarCover").fadeIn();
  2422. leftMenuShown = true;
  2423. }
  2424. }
  2425. function hideLeftMenu(){
  2426. if (leftMenuShown){
  2427. $("#leftSideBar").animate({left: $("#leftSideBar").width() * -1}, 120,function(){
  2428. $("#leftSideBar").hide();
  2429. });
  2430. $("#sideBarCover").fadeOut();
  2431. leftMenuShown = false;
  2432. }
  2433. }
  2434. function showFileInformation(){
  2435. ao_module_agirun("Music/functions/getFileInfo.js", {
  2436. filepath: playingFileDetail[1],
  2437. },function(data){
  2438. //console.log(data);
  2439. $("#settingInterface").hide();
  2440. $("#filepropInterface").show();
  2441. $("#filepropInterface").find(".filename").text(ao_module_codec.decodeUmFilename(data[0]));
  2442. $("#filepropInterface").find(".rawname").text(data[0]);
  2443. $("#filepropInterface").find(".filepath").text(data[1]);
  2444. $("#filepropInterface").find(".filesize").text(data[2] + " (" + data[3] + " Bytes)");
  2445. $("#filepropInterface").find(".filedate").text(data[4]);
  2446. });
  2447. }
  2448. function resizeQuickAdjust(){
  2449. //Resize the position of the leftMenu
  2450. if (!leftMenuShown){
  2451. $("#leftSideBar").css("left", $("#leftSideBar").width() * -1);
  2452. }
  2453. if ($("#playerInterface").offset().left != 0){
  2454. $("#playerInterface").css("left",window.innerWidth);
  2455. }
  2456. $("#albumnArtImage").css("max-height",window.innerHeight - 255);
  2457. setTimeout(function(){
  2458. $("#albumnArt").css({
  2459. "height": window.innerHeight - 255,
  2460. "top": (window.innerHeight / 2 - $("#albumnArtImage").height()/2)
  2461. });
  2462. },50);
  2463. //var imageTop = (window.innerHeight - 255 - $("#albumnArtImage").height()) / 2;
  2464. //$("#albumnArtImage").css("top",imageTop + "px");
  2465. }
  2466. function setStorage(configName,configValue){
  2467. ao_module_storage.setStorage("AirMusic",configName,configValue);
  2468. /*
  2469. $.ajax({
  2470. type: 'GET',
  2471. url: "../system/file_system/preference",
  2472. data: {key: "AirMusic/" + configName,value:configValue},
  2473. success: function(data){},
  2474. async:true
  2475. });
  2476. */
  2477. return true;
  2478. }
  2479. function loadStorage(configName){
  2480. /*
  2481. var result = "";
  2482. $.ajax({
  2483. type: 'GET',
  2484. url: "../system/file_system/preference",
  2485. data: {key: "AirMusic/" + configName},
  2486. success: function(data){
  2487. if (data.error !== undefined){
  2488. result = "";
  2489. }else{
  2490. result = data;
  2491. }
  2492. },
  2493. error: function(data){result = "";},
  2494. async:false,
  2495. timeout: 3000
  2496. });
  2497. return result;
  2498. */
  2499. return ao_module_storage.loadStorage("AirMusic",configName);
  2500. }
  2501. //Wipe controller for mobile users
  2502. $("#albumnArt")[0].addEventListener('touchstart', handleTouchStart, false);
  2503. $("#albumnArt")[0].addEventListener('touchmove', handleTouchMove, false);
  2504. var xDown = null;
  2505. var yDown = null;
  2506. function getTouches(evt) {
  2507. return evt.touches || // browser API
  2508. evt.originalEvent.touches; // jQuery
  2509. }
  2510. function handleTouchStart(evt) {
  2511. const firstTouch = getTouches(evt)[0];
  2512. xDown = firstTouch.clientX;
  2513. yDown = firstTouch.clientY;
  2514. };
  2515. function handleTouchMove(evt) {
  2516. if ( ! xDown || ! yDown ) {
  2517. return;
  2518. }
  2519. var xUp = evt.touches[0].clientX;
  2520. var yUp = evt.touches[0].clientY;
  2521. var xDiff = xDown - xUp;
  2522. var yDiff = yDown - yUp;
  2523. if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) {/*most significant*/
  2524. if ( xDiff > 0 ) {
  2525. /* left swipe */
  2526. //Going to the next song
  2527. nextSong();
  2528. } else {
  2529. /* right swipe */
  2530. //Going back one song
  2531. previousSong();
  2532. }
  2533. } else {
  2534. if ( yDiff > 0 ) {
  2535. /* up swipe */
  2536. } else {
  2537. /* down swipe */
  2538. }
  2539. }
  2540. /* reset values */
  2541. xDown = null;
  2542. yDown = null;
  2543. };
  2544. //Handle audio progress to time conversion
  2545. function secondsToHms(d) {
  2546. d = Number(d);
  2547. var h = Math.floor(d / 3600);
  2548. var m = Math.floor(d % 3600 / 60);
  2549. var s = Math.floor(d % 3600 % 60);
  2550. if (h > 0 && h < 10){
  2551. dh = "0" + h + ":";
  2552. }else if (h == 0){
  2553. dh = "";
  2554. }else{
  2555. dh = h + ":";
  2556. }
  2557. if (m > 0 && m < 10){
  2558. dm = "0" + m + ":";
  2559. }else if (m == 0){
  2560. if (h > 0){
  2561. dm = "00:";
  2562. }else{
  2563. dm = "0:";
  2564. }
  2565. }else{
  2566. dm = m + ":";
  2567. }
  2568. if (s > 0 && s < 10){
  2569. ds = "0" + s;
  2570. }else if (s == 0){
  2571. if (m > 0 || h > 0){
  2572. ds = "00";
  2573. }else{
  2574. ds = "00";
  2575. }
  2576. }else{
  2577. ds = s;
  2578. }
  2579. return dh + dm + ds;
  2580. }
  2581. //Handle window resize events
  2582. $(window).on("resize", function(){
  2583. resizeQuickAdjust();
  2584. });
  2585. function AllQuickMenuHidden(){
  2586. var result = true;
  2587. $(".quickMenu").each(function(){
  2588. if ( $(this).is(':visible') ){
  2589. result = false;
  2590. }
  2591. });
  2592. return result;
  2593. }
  2594. function AllSubMenuHidden(){
  2595. var result = true;
  2596. $(".showMoreMenus").each(function(){
  2597. if ( $(this).is(':visible') ){
  2598. result = false;
  2599. }
  2600. });
  2601. return result;
  2602. }
  2603. //Handle back button press on mobile devices
  2604. function handleBackButton() {
  2605. if (!AllQuickMenuHidden()){
  2606. hideAllquickMenu();
  2607. window.history.pushState({}, '');
  2608. }else if (mainPlayerShown()){
  2609. //Close the main Menu
  2610. hideMainPlayerInterface();
  2611. window.history.pushState({}, '');
  2612. }else if (!AllSubMenuHidden()){
  2613. $(".showMoreMenus").fadeOut('fast');
  2614. $("#showmoreUIcover").fadeOut('fast');
  2615. window.history.pushState({}, '');
  2616. }else{
  2617. window.history.back();
  2618. }
  2619. }
  2620. window.addEventListener('popstate', handleBackButton);
  2621. window.history.pushState({}, '');
  2622. </script>
  2623. </body>
  2624. </html>