index.html 104 KB

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