index.html 92 KB

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