index.html 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538
  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. function enterSearchMode(){
  509. if (searchModeEnabled){
  510. //Search mode already enabled
  511. return;
  512. }
  513. $("#searchModeMenu").show();
  514. $("#mainMenu").hide();
  515. preSearchItemBuffer = [$("#mainList").html(),$("#interfaceTitle").text(),$("#AMmenuIcon").attr("class")];
  516. searchModeEnabled = true;
  517. }
  518. function exitSearchMode(){
  519. $("#searchModeMenu").hide();
  520. $("#mainMenu").show();
  521. $("#searchInputBar").val("");
  522. if (preSearchItemBuffer != ""){
  523. //If previous record exists, recover the previous view from storage
  524. $("#mainList").html(preSearchItemBuffer[0]);
  525. $("#interfaceTitle").text(preSearchItemBuffer[1]);
  526. $("#AMmenuIcon").attr("class",preSearchItemBuffer[2])
  527. preSearchItemBuffer = "";
  528. }
  529. searchModeEnabled = false;
  530. }
  531. document.getElementById("searchInputBar").addEventListener("keypress", function(event){
  532. console.log(event, event.keyCode);
  533. if(event.keyCode == 13){
  534. //Enter pressed. start searching
  535. searchSong();
  536. }
  537. });
  538. /*
  539. function handleSearchInputEnter(e){
  540. if(e.keyCode == 13){
  541. //Enter pressed. start searching
  542. searchSong();
  543. }
  544. }
  545. */
  546. function searchSong(){
  547. var keyword = $("#searchInputBar").val();
  548. if (keyword.includes("?") || keyword.includes("&")){
  549. alert("Search keyword cannot contains & or ? symbol.");
  550. return;
  551. }
  552. if (keyword == ""){
  553. //Empty keyword. Return nothing
  554. return;
  555. }
  556. //Clear the mainList, replace with a dummy loading screen
  557. $("#mainList").html('<div class="mainList item whiteFont">\
  558. <div class="ui header" style="margin:0px !important;padding-bottom:15px;padding-top:5px;">\
  559. <i class="loading spinner icon whiteFont" style="overflow:hidden;margin-top:5px;"></i>\
  560. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%;">\
  561. Searching...\
  562. </div>\
  563. </div>\
  564. <div class="topRightCorner" align="center">\
  565. -1\
  566. </div>\
  567. </div>');
  568. ao_module_agirun("Music/functions/listSong.js", {
  569. listSong: "search:" + keyword
  570. }, function(data){
  571. currentPath = "";
  572. var template = '<div class="mainList file item" filepath={filepath} id={id} rawname={rawname}>\
  573. <div class="ui header selectable" style="margin:0px !important;" onClick="playSong(this);">\
  574. <img class="ui small image" src="img/eq.svg" style="margin-right: 0.2em;"></img>\
  575. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%;">\
  576. {songtitle}\
  577. <div class="sub header fileinfo" style="color: #c7c7c7;">{ext} / {size}</div>\
  578. </div>\
  579. </div>\
  580. <div class="topRightCorner" align="center">\
  581. {id}\
  582. </div>\
  583. <div class="mainList rightFunctionBar" align="center" onClick="showMore(this);">\
  584. <i class="ellipsis vertical icon" style="top: 2em;"></i>\
  585. </div>\
  586. </div>';
  587. if ($("#searchModeMenu").is(":hidden")){
  588. //The user exited search mode before the search results come back
  589. //Dispose the search result
  590. return;
  591. }
  592. if (data.length == 0){
  593. //No search results.
  594. $("#mainList").html("");
  595. $("#mainList").append('<div class="mainList item whiteFont">\
  596. <div class="ui header" style="margin:0px !important;padding-bottom:15px;padding-top:5px;">\
  597. <i class="remove icon whiteFont" style="overflow:hidden;margin-top:5px;"></i>\
  598. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%;">\
  599. No result for keyword: ' + keyword + '.\
  600. </div>\
  601. </div>\
  602. <div class="topRightCorner" align="center">\
  603. -1\
  604. </div>\
  605. </div>');
  606. return;
  607. }
  608. $("#interfaceTitle").text("Search");
  609. $("#AMmenuIcon").attr("class","search icon large whiteFont")
  610. //Initialize the song list
  611. displayList = data;
  612. if (playingList == []){
  613. playingList = Array.from(displayList);
  614. }
  615. $("#mainList").html("");
  616. for ( var i =0; i < data.length; i++){
  617. var songInfo = data[i];
  618. var path = songInfo[0];
  619. var displayname = ao_module_codec.decodeUmFilename(songInfo[1]);
  620. var ext = songInfo[2];
  621. var size = songInfo[3];
  622. var box = template;
  623. box = replaceAll("{filepath}",ao_module_utils.objectToAttr(path),box);
  624. box = replaceAll("{id}",i + 1,box); //User count from 1
  625. box = replaceAll("{rawname}",ao_module_utils.objectToAttr(songInfo[1]),box);
  626. box = replaceAll("{songtitle}",displayname,box);
  627. box = replaceAll("{ext}",ext,box);
  628. box = replaceAll("{size}",size,box);
  629. $("#mainList").append(box);
  630. }
  631. totalMusicCount = data.length;
  632. $("#mainList").append("<br><br><br><br><br><br><br>");
  633. $("#interfaceDetails").text("[" + i + " songs]");
  634. highLightPlayingMusic();
  635. loadThumbnailToMusicList(".mainList.file.item");
  636. });
  637. }
  638. function enterRemotePlayID(object){
  639. var id = $(object).text().trim();
  640. $("#remotePlayID").val($("#remotePlayID").val() + id);
  641. }
  642. function ridOpr(opr){
  643. if (opr == 'backspace'){
  644. var currentText = $("#remotePlayID").val();
  645. var newText = currentText.substring(0,currentText.length - 1);
  646. $("#remotePlayID").val(newText);
  647. }else if (opr == 'reset'){
  648. $("#remotePlayID").val("");
  649. }
  650. }
  651. function openInFileExplorer(){
  652. var dirname = playingFileDetail[1].split("/");
  653. var fname = dirname.pop(); //Pop away the filename
  654. dirname = dirname.join("/") + "/";
  655. var path = dirname;
  656. if (dirname.substring(0,1) != "/"){
  657. //This is not absolute path. Start the path from airMusic
  658. path = "AirMusic/" + dirname;
  659. }
  660. path = path.replace("media?file=","");
  661. if (path.substring(0,1) == "/"){
  662. path = path.substring(1)
  663. }
  664. ao_module_openPath(path, fname);
  665. }
  666. //quickmenu Functions
  667. function hideAllquickMenu(){
  668. $(".quickMenu").fadeOut('fast');
  669. $("#fadeReturnScreen").fadeOut('fast');
  670. }
  671. //Setting related function
  672. function showSettingInterface(){
  673. $("#settingInterface").fadeIn('fast');
  674. $("#fadeReturnScreen").fadeIn('fast');
  675. //Update contents in the setting menu
  676. $("#settingMenuTitle").text($("#mainPlayerSongTitle").text());
  677. }
  678. //Timer related functions
  679. function showTimerInterface(){
  680. $("#timerInterface").fadeIn('fast');
  681. $("#fadeReturnScreen").fadeIn('fast');
  682. }
  683. function initPlaylistInterfaceList(){
  684. $("#existsingPlaylist").html("");
  685. //Get the playlist list from server side
  686. ao_module_agirun("Music/functions/playlist.js", {
  687. opr: "root"
  688. }, function(data){
  689. data.forEach(playlist => {
  690. $("#existsingPlaylist").append(`<div class="playlist item selectable whiteFont" name="${playlist.name}" onclick="addSongToSelectedPlaylist(this);">
  691. <i class="list icon whiteFont"></i> ${playlist.name} [${playlist.count} files]
  692. </div>`);
  693. })
  694. });
  695. }
  696. function showPlaylistInterface(){
  697. initPlaylistInterfaceList();
  698. $("#playlistInterface").fadeIn('fast');
  699. $("#fadeReturnScreen").fadeIn('fast');
  700. }
  701. function addToThisPlaylist(){
  702. }
  703. $("#stopMode").change(function () {
  704. var end = this.value;
  705. if (end.includes("Fade Out & Stop")){
  706. //Start fading out the volume
  707. timerEndMode = "fade";
  708. setStorage("timerEndMode","fade");
  709. }else{
  710. //End immediately
  711. timerEndMode = "end";
  712. setStorage("timerEndMode","end");
  713. }
  714. });
  715. var fadeOutStepping = 0.1; //The steps size for fading out during timer countdown
  716. var defaultVolumeBeforeFadeout = 0;
  717. function toggleCountDown(button){
  718. if (!timerMode){
  719. //Start count down
  720. timerMode = true;
  721. $(button).text("Stop");
  722. timerRemaining = ((parseInt($("#timerHour").text()) * 60) + parseInt($("#timerMinute").text())) * 60; //in seconds
  723. if (timerRemaining <= 0){
  724. //Start with 0
  725. timerMode = false;
  726. $(button).text("Start");
  727. return;
  728. }
  729. //Update the value on the remaining counter
  730. $("#remainingUI").text(parseTimer(timerRemaining));
  731. $("#timerSettingInterface").slideUp('fast');
  732. $("#timerCountingInterface").slideDown('fast');
  733. $("#stopMode").attr("disabled","");
  734. defaultVolumeBeforeFadeout = audioElement[0].volume;
  735. fadeOutStepping = (audioElement[0].volume) / timerRemaining;
  736. progressCounter();
  737. }else{
  738. //Stop count down
  739. timerMode = false;
  740. $(button).text("Start");
  741. timerRemaining = 0;
  742. $("#timerSettingInterface").slideDown('fast');
  743. $("#timerCountingInterface").slideUp('fast');
  744. $("#stopMode").removeAttr("disabled");
  745. }
  746. }
  747. function progressCounter(){
  748. //Update the timer
  749. timerRemaining = timerRemaining - 1;
  750. $("#remainingUI").text(parseTimer(timerRemaining));
  751. if (timerRemaining > 0){
  752. //Continues
  753. if (timerEndMode == "fade"){
  754. var newvol = audioElement[0].volume - fadeOutStepping;
  755. audioElement[0].volume = Math.max(0,newvol);
  756. }
  757. setTimeout(progressCounter,1000);
  758. }else{
  759. //Times up
  760. handleTimerEnd();
  761. }
  762. }
  763. function handleTimerEnd(){
  764. //Stop the playback
  765. originalVol = audioElement[0].volume;
  766. fadeAudio();
  767. setPlaying(false);
  768. audioElement[0].pause();
  769. setTimeout(function(){
  770. audioElement[0].volume = defaultVolumeBeforeFadeout;
  771. },500);
  772. }
  773. function parseTimer(remainingTime){
  774. //remainingTime in seconds, prase to HH:mm:ss
  775. var hours = Math.floor(remainingTime / 3600);
  776. var remainingTime = remainingTime % 3600;
  777. var minutes = Math.floor(remainingTime / 60);
  778. var seconds = remainingTime % 60;
  779. if (minutes < 10){
  780. minutes = "0" + minutes;
  781. }
  782. if (seconds < 10){
  783. seconds = "0" + seconds;
  784. }
  785. var formatted = hours + ":" + minutes + ":" + seconds;
  786. return formatted;
  787. }
  788. function addTimer(unit,value){
  789. if (unit == "h"){
  790. if (value == "r"){
  791. $("#timerHour").text("0");
  792. }else{
  793. $("#timerHour").text($("#timerHour").text() - -1 * value);
  794. }
  795. }else if (unit == "m"){
  796. if (value == "r"){
  797. $("#timerMinute").text("0");
  798. }else{
  799. $("#timerMinute").text($("#timerMinute").text() - -1 * value);
  800. }
  801. }
  802. if (parseInt($("#timerHour").text()) < 0){
  803. $("#timerHour").text("0");
  804. }
  805. if (parseInt($("#timerMinute").text()) < 0){
  806. if (parseInt($("#timerHour").text()) > 0){
  807. //subtract 1 from the hour
  808. $("#timerHour").text($("#timerHour").text() - 1);
  809. $("#timerMinute").text(parseInt($("#timerMinute").text()) + 60);
  810. }else{
  811. //There is no hours to subtract
  812. $("#timerMinute").text("0");
  813. }
  814. }
  815. if (parseInt($("#timerMinute").text()) > 59){
  816. $("#timerMinute").text(parseInt($("#timerMinute").text()) - 60);
  817. $("#timerHour").text($("#timerHour").text() - -1);
  818. }
  819. }
  820. //Download function
  821. function downloadPlayingSong(){
  822. var url = audioElement.attr("src");
  823. var ext = url.split(".").pop();
  824. var filename = $("#mainPlayerSongTitle").text().trim();
  825. generateDownloadElement(url,filename);
  826. /*
  827. if (url.includes("/media")){
  828. blobDownloadElement(url,filename);
  829. }else{
  830. generateDownloadElement(url,filename);
  831. }
  832. */
  833. }
  834. var downloadInProgress = false;
  835. function blobDownloadElement(filepath,filename){
  836. if (downloadInProgress){
  837. alert("Please wait until another download finished.");
  838. return;
  839. }
  840. downloadInProgress = true;
  841. $("#downloadBtn").find("i").addClass("disabled");
  842. $("#downloadProgressBar").find(".bar").css("width","0%");
  843. $("#downloadProgressBar").show();
  844. var xhr = new XMLHttpRequest();
  845. xhr.onreadystatechange = function(){
  846. if (this.readyState == 4 && this.status == 200){
  847. //handler(this.response);
  848. //console.log(this.response, typeof this.response);
  849. var url = window.URL || window.webkitURL;
  850. //Open the downloaded data in new window for testing
  851. //window.open(url.createObjectURL(this.response));
  852. generateDownloadElement(url.createObjectURL(this.response),filename);
  853. $("#downloadBtn").find("i").removeClass("disabled");
  854. $("#downloadProgressBar").hide();
  855. downloadInProgress = false;
  856. }
  857. }
  858. xhr.onprogress = function (event) {
  859. console.log("[AirMusic] Download Progress: " + event.loaded + " / " + event.total + "Bytes");
  860. $("#downloadProgressBar").find(".bar").css("width",(event.loaded / event.total) * 100 + "%");
  861. };
  862. xhr.open('GET', filepath);
  863. xhr.responseType = 'blob';
  864. xhr.send();
  865. }
  866. function generateDownloadElement(filepath, filename){
  867. var link = document.createElement('a');
  868. //Clean the filepath
  869. filepath = filepath.split("//").join("/");
  870. //Convert the filepath to download path
  871. link.href = filepath.replace("/media?file=", "/media/download/?file=");
  872. //Generate the download element
  873. link.setAttribute('download', filename);
  874. document.getElementsByTagName("body")[0].appendChild(link);
  875. // Firefox
  876. if (document.createEvent) {
  877. var event = document.createEvent("MouseEvents");
  878. event.initEvent("click", true, true);
  879. link.dispatchEvent(event);
  880. }
  881. // IE
  882. else if (link.click) {
  883. link.click();
  884. }
  885. link.parentNode.removeChild(link);
  886. }
  887. //Volume control related features
  888. var previousAudioVolume = 0;
  889. function mute(button){
  890. if (audioElement[0].volume != 0){
  891. //Set to mute
  892. previousAudioVolume = audioElement[0].volume;
  893. audioElement[0].volume = 0;
  894. $(button).css("opacity", "1");
  895. $("#voldownBtn").addClass("disabled");
  896. $("#volupBtn").addClass("disabled");
  897. }else{
  898. //Restore from mute
  899. audioElement[0].volume = previousAudioVolume;
  900. $(button).css("opacity", "0.6");
  901. $("#voldownBtn").removeClass("disabled");
  902. $("#volupBtn").removeClass("disabled");
  903. }
  904. $("#volBar").css("width",audioElement[0].volume * 100 + "%");
  905. }
  906. var volbarTimeoutEvt;
  907. function addAudioVolume(value){
  908. $("#volumeGUI").slideDown('fast');
  909. if (volbarTimeoutEvt !== undefined){
  910. clearTimeout(volbarTimeoutEvt);
  911. }
  912. volbarTimeoutEvt = setTimeout(function(){
  913. $("#volumeGUI").slideUp('fast');
  914. },3000);
  915. $("#volumeGUI")
  916. if (audioElement[0].volume + value >= 1){
  917. audioElement[0].volume = 1;
  918. }else if (audioElement[0].volume + value <= 0){
  919. audioElement[0].volume = 0;
  920. }else{
  921. audioElement[0].volume += value;
  922. }
  923. $("#volBar").css("width",Math.min(100,audioElement[0].volume * 100) + "%");
  924. }
  925. function updatePlaybackDisplayTime(currentTime,duration){
  926. let progress = Math.round(currentTime);
  927. let remainTime = Math.round(duration - currentTime);
  928. $("#progressTime").text(secondsToHms(progress));
  929. if (!isNaN(remainTime)){
  930. $("#remainTime").text("-" + secondsToHms(remainTime));
  931. }
  932. }
  933. function nextSongHandler(){
  934. console.log("Next song");
  935. if (repeatMode == 1){
  936. //Next song in the playlist
  937. if (randomMode){
  938. var randomTrackID = Math.floor(Math.random() * (playingList.length - 1));
  939. //console.log(randomTrackID, playingList[randomTrackID]);
  940. nextSong(randomTrackID,true);
  941. }else{
  942. var playingSongIndex = playingFileDetail[0];
  943. var nextSongIndex = playingSongIndex;
  944. if (nextSongIndex >= playingList.length){
  945. nextSongIndex = 0;
  946. }
  947. //console.log(playingSongIndex, nextSongIndex);
  948. nextSong(nextSongIndex,true);
  949. }
  950. }else if (repeatMode == 2){
  951. //Loop this song only
  952. audioElement[0].pause();
  953. audioElement[0].currentTime = 0;
  954. audioElement[0].play();
  955. }else if (repeatMode == 0){
  956. //Pause after finish this song
  957. setPlaying(false);
  958. audioElement[0].pause();
  959. audioElement[0].currentTime = 0;
  960. }
  961. }
  962. function mainPlayerShown(){
  963. if ($("#playerInterface").offset().left == 0){
  964. return true;
  965. }
  966. return false;
  967. }
  968. function toggleRandomMode(button){
  969. var btn = $(button).find("i");
  970. if (randomMode){
  971. //Set the random mode to false
  972. btn.removeClass("enabled").addClass("disabled");
  973. randomMode = false;
  974. }else{
  975. btn.removeClass("disabled").addClass("enabled");
  976. randomMode = true;
  977. }
  978. setStorage("randomMode",randomMode);
  979. }
  980. function toggleRepeatMode(button){
  981. if (repeatMode == 0){
  982. setRepeatMode(1,button);
  983. setStorage("repeatMode",1);
  984. }else if (repeatMode == 1){
  985. setRepeatMode(2,button);
  986. setStorage("repeatMode",2);
  987. }else if (repeatMode == 2){
  988. setRepeatMode(0,button);
  989. setStorage("repeatMode",0);
  990. }
  991. }
  992. function setRepeatMode(modeCode,button){
  993. if (modeCode == 1){
  994. //Set repeat mode to "Repeat all"
  995. $(button).find(".singleLoop").hide();
  996. $(button).find("i").removeClass("disabled").addClass("enabled");
  997. repeatMode = 1;
  998. }else if (modeCode == 2){
  999. //Set repeat mode to "Repeat one"
  1000. $(button).find(".singleLoop").show();
  1001. $(button).find("i").removeClass("disabled").addClass("enabled");
  1002. repeatMode = 2;
  1003. }else if (modeCode == 0){
  1004. //Set repeat mode to "None"
  1005. $(button).find(".singleLoop").hide();
  1006. $(button).find("i").removeClass("enabled").addClass("disabled");
  1007. repeatMode = 0;
  1008. }
  1009. }
  1010. function hideMainPlayerInterface(){
  1011. $("#playerInterface").animate({left: window.innerWidth},300);
  1012. $("body").css("overflow-y","auto");
  1013. }
  1014. function showMainPlayerInterface(){
  1015. $("#playerInterface").animate({left:0},300);
  1016. $("body").css("overflow-y","hidden");
  1017. }
  1018. function syncSystemVol(){
  1019. //Initiate the module's volume to the system's
  1020. var globalvol = localStorage.getItem("global_volume");
  1021. //console.log("Global Volume" + globalvol.toString());
  1022. if (!globalvol){
  1023. globalvol = 0.1;
  1024. }
  1025. //Check if it is mobile. If yes, always 100% and leave volume to system
  1026. if (isMobile()){
  1027. globalvol = 1;
  1028. //$(".desktopOnly").addClass("disabled");
  1029. }
  1030. audioElement[0].volume = parseFloat(globalvol);
  1031. $("#volBar").css("width",audioElement[0].volume * 100 + "%");
  1032. }
  1033. function replaceAll(target, replace, original){
  1034. return original.split(target).join(replace);
  1035. };
  1036. function playSong(object, startPaused = false){
  1037. if ($(object).parent().hasClass("playingTrack")){
  1038. //This is already the song that is currently playing. Show the main player interface instead.
  1039. showMainPlayerInterface();
  1040. resizeQuickAdjust();
  1041. return;
  1042. }
  1043. //$(".playingTrack").removeClass("playingTrack");
  1044. //$(object).parent().addClass("playingTrack");
  1045. var filepath = ao_module_utils.attrToObject($(object).parent().attr('filepath'));
  1046. var rawname = ao_module_utils.attrToObject($(object).parent().attr('rawname'));
  1047. var displayName = ao_module_codec.decodeUmFilename(rawname);
  1048. var info = $(object).parent().find(".fileinfo").text();
  1049. var id = $(object).parent().attr('id');
  1050. if (id === undefined){
  1051. //This might be a file from dropdown list. use listid instead
  1052. id = $(object).parent().attr('listid');
  1053. }
  1054. updateMiniPlayerUI(displayName,info,id);
  1055. //Check if page mode is enabled. If yes, do auto tab switch
  1056. if (pagingEnabled){
  1057. var targetPageNumber = getPageNumberByPlaybackId(parseInt(id));
  1058. switchToPage(targetPageNumber);
  1059. }
  1060. //Seperate out the filepath without media server path
  1061. var fileVpath = filepath.split("=")[1];
  1062. updateMainPlayerUI(displayName,info,id, fileVpath);
  1063. loadAndPlayAudioFile(filepath, !startPaused);
  1064. if (!currentPlaying && !startPaused){
  1065. setPlaying(true);
  1066. }
  1067. playingFileDetail = [parseInt(id),filepath];
  1068. //If the user play this file, assume the next file to be added to playlist is this file
  1069. playlistAddPendingFile = filepath;
  1070. //Have a backup of the current list just incase the user open another directory while a list is playing
  1071. //Only backup when it is not call from dropdown list
  1072. if (!$(object).parent().hasClass("dropdownList")){
  1073. playingList = Array.from(displayList);
  1074. }
  1075. parsePlayingSongList();
  1076. if ($("#miniPlayer").hasClass("hidden")){
  1077. //This is the first song that has played after the UI init
  1078. $("#miniPlayer").css("display","none").removeClass("hidden").slideDown();
  1079. }
  1080. showMainPlayerInterface();
  1081. //Just in case the albumn image changed, albumn art css is also updated.
  1082. resizeQuickAdjust();
  1083. updateStateReferingURL();
  1084. highLightPlayingMusic();
  1085. }
  1086. function loadThumbnailToMusicList(selector = ".mainList.file.item"){
  1087. $(selector).each(function(){
  1088. let filepath = JSON.parse(decodeURIComponent($(this).attr("filepath")));
  1089. let thisFileItemID = $(this).attr("id");
  1090. let rawname = JSON.parse(decodeURIComponent($(this).attr("rawname")));
  1091. let realVpath = filepath.split("=");
  1092. realVpath.shift();
  1093. realVpath = realVpath.join("=");
  1094. //console.log(thisFileItemID, realVpath, rawname);
  1095. //Load the thumbnail for this item in list
  1096. ao_module_agirun("Music/functions/getThumbnail.js", {
  1097. file: realVpath,
  1098. }, function(data){
  1099. if (data.error !== undefined){
  1100. }else{
  1101. $("#" + thisFileItemID).find("img").attr("src","data:image/jpg;base64," + data);
  1102. $(".dropdownList.file.item").each(function(){
  1103. var thisFilepath = JSON.parse(decodeURIComponent($(this).attr("filepath")));
  1104. if ($(this).attr("listid") == thisFileItemID && thisFilepath == filepath){
  1105. $(this).find("img").attr("src","data:image/jpg;base64," + data);
  1106. }
  1107. })
  1108. }
  1109. });
  1110. })
  1111. }
  1112. function loadThumbnail(filepath){
  1113. //Load the thumbnail
  1114. var realVpath = filepath.split("=");
  1115. realVpath.shift();
  1116. realVpath = realVpath.join("=");
  1117. ao_module_agirun("Music/functions/getThumbnail.js", {
  1118. file: realVpath,
  1119. }, function(data){
  1120. if (data.error !== undefined){
  1121. console.log(data.error)
  1122. $("#albumnArtImage").attr("src","img/default.png");
  1123. $("#smallPlayerThumb").attr("src","img/default.png");
  1124. if (navigator.mediaSession.metadata){
  1125. navigator.mediaSession.metadata.artwork = [
  1126. { src: "img/default.png", sizes: '512x512', type: 'image/png' }
  1127. ]
  1128. }
  1129. }else{
  1130. $("#albumnArtImage").attr("src","data:image/jpg;base64," + data);
  1131. $("#smallPlayerThumb").attr("src","data:image/jpg;base64," + data);
  1132. if (isAndroid && navigator.mediaSession.metadata){
  1133. //Android
  1134. navigator.mediaSession.metadata.artwork = [
  1135. { src: "data:image/jpg;base64," + data, sizes: '480x480', type: 'image/jpg' }
  1136. ]
  1137. }
  1138. }
  1139. resizeQuickAdjust();
  1140. });
  1141. }
  1142. function nextSong(id = false,forcePlayEvenStopped = false){
  1143. //Check if the current playlist has more than one songs.
  1144. var currentPaused = audioElement[0].paused;
  1145. if (playingList.length > 1){
  1146. var nextSongIndex = playingFileDetail[0];
  1147. if (id != false){
  1148. //Allow manual overwrite for this function
  1149. nextSongIndex = id;
  1150. var nextSong = playingList[nextSongIndex];
  1151. }else{
  1152. if (playingFileDetail[0] >= playingList.length){
  1153. var nextSong = playingList[0]; //Back to the first song in list
  1154. nextSongIndex = 0;
  1155. }else{
  1156. var nextSong = playingList[nextSongIndex]; //Index of the playList + 1 as the index for the files is alrady i+1. (User count from one)
  1157. }
  1158. }
  1159. //The songs has to be play via background services instead of relying on DOM
  1160. var filepath = nextSong[0];
  1161. var rawname = nextSong[1];
  1162. var displayName = ao_module_codec.decodeUmFilename(rawname);
  1163. var info = nextSong[2] + " / " + nextSong[3];
  1164. var id = nextSongIndex + 1;
  1165. updateMiniPlayerUI(displayName,info,id);
  1166. //Seperate out the filepath without media server path
  1167. var fileVpath = filepath.split("=")[1];
  1168. updateMainPlayerUI(displayName,info,id, fileVpath);
  1169. if (forcePlayEvenStopped){
  1170. loadAndPlayAudioFile(filepath,true);
  1171. }else{
  1172. loadAndPlayAudioFile(filepath,!currentPaused);
  1173. }
  1174. if (currentPlaying){
  1175. setPlaying(true);
  1176. }
  1177. playingFileDetail = [id,filepath];
  1178. //Need not to update the playlist because it is the same
  1179. if (pagingEnabled){
  1180. var targetPageNumber = getPageNumberByPlaybackId(parseInt(id));
  1181. switchToPage(targetPageNumber, function(){
  1182. highLightPlayingMusic();
  1183. parsePlayingSongList();
  1184. });
  1185. }else{
  1186. highLightPlayingMusic();
  1187. }
  1188. }else{
  1189. //This is the only song in playlist. Play again from start
  1190. audioElement[0].pause();
  1191. audioElement[0].currentTime = 0;
  1192. if (!currentPaused){
  1193. audioElement[0].play();
  1194. }
  1195. }
  1196. updateStateReferingURL();
  1197. }
  1198. function previousSong(){
  1199. var currentPaused = audioElement[0].paused;
  1200. if (playingList.length > 1){
  1201. var nextSongIndex = playingFileDetail[0] - 1;
  1202. if (nextSongIndex == 0){
  1203. nextSongIndex = playingList.length;
  1204. var nextSong = playingList[nextSongIndex - 1]; //Back to the last song in list
  1205. }else{
  1206. 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)
  1207. }
  1208. //The songs has to be play via background services instead of relying on DOM
  1209. var filepath = nextSong[0];
  1210. var rawname = nextSong[1];
  1211. var displayName = ao_module_codec.decodeUmFilename(rawname);
  1212. var info = nextSong[2] + " / " + nextSong[3];
  1213. var id = nextSongIndex;
  1214. updateMiniPlayerUI(displayName,info,id);
  1215. //Seperate out the filepath without media server path
  1216. var fileVpath = filepath.split("=")[1];
  1217. updateMainPlayerUI(displayName,info,id, fileVpath);
  1218. loadAndPlayAudioFile(filepath,!currentPaused);
  1219. if (currentPlaying){
  1220. setPlaying(true);
  1221. }
  1222. playingFileDetail = [id,filepath];
  1223. //Need not to update the playlist because it is the same
  1224. if (pagingEnabled){
  1225. var targetPageNumber = getPageNumberByPlaybackId(parseInt(id));
  1226. switchToPage(targetPageNumber, function(){
  1227. highLightPlayingMusic();
  1228. parsePlayingSongList();
  1229. });
  1230. }else{
  1231. highLightPlayingMusic();
  1232. }
  1233. }else{
  1234. //This is the only song in playlist. Play again from start
  1235. audioElement[0].pause();
  1236. audioElement[0].currentTime = 0;
  1237. audioElement[0].play();
  1238. }
  1239. updateStateReferingURL();
  1240. }
  1241. var originalVol = 0;
  1242. function togglePlayMode(){
  1243. if (currentPlaying){
  1244. originalVol = audioElement[0].volume;
  1245. fadeAudio();
  1246. setPlaying(false);
  1247. }else{
  1248. gainAudio();
  1249. setPlaying(true);
  1250. }
  1251. }
  1252. let audioTransitioning = false;
  1253. function fadeAudio(){
  1254. audioTransitioning = true;
  1255. if(audioElement[0].volume > 0){
  1256. var testval = audioElement[0].volume - 0.1;
  1257. audioElement[0].volume = Math.max(0,testval);
  1258. setTimeout(fadeAudio, 50);
  1259. }else{
  1260. audioElement[0].pause();
  1261. setTimeout(function(){
  1262. audioElement[0].volume = originalVol;
  1263. updateStateReferingURL();
  1264. audioTransitioning = false;
  1265. }, 100);
  1266. }
  1267. }
  1268. var targetVol = 0;
  1269. function gainAudio(){
  1270. targetVol = audioElement[0].volume;
  1271. audioElement[0].volume = 0;
  1272. setTimeout(function(){
  1273. audioElement[0].play();
  1274. recursiveGainAudio();
  1275. }, 100);
  1276. }
  1277. function recursiveGainAudio(){
  1278. audioTransitioning = true;
  1279. if(audioElement[0].volume < targetVol){
  1280. if (audioElement[0].volume + 0.1 < 1){
  1281. audioElement[0].volume += 0.1
  1282. }else{
  1283. //Audio volume larger than 1, make it 1
  1284. audioElement[0].volume = 1
  1285. }
  1286. setTimeout(recursiveGainAudio, 50);
  1287. }else{
  1288. setTimeout(function(){
  1289. audioElement[0].volume = targetVol;
  1290. updateStateReferingURL();
  1291. audioTransitioning = false;
  1292. }, 100);
  1293. }
  1294. }
  1295. //Update all icons on play and pause buttons
  1296. function setPlaying(playing){
  1297. if (playing == true){
  1298. $(".PlayButton").attr("class","pause icon whiteFont PlayButton");
  1299. currentPlaying = true;
  1300. }else{
  1301. $(".PlayButton").attr("class","play icon whiteFont PlayButton");
  1302. currentPlaying = false;
  1303. }
  1304. }
  1305. function loadAndPlayAudioFile(sourceURL,playAfterLoad = true){
  1306. var audio = audioElement;
  1307. //These was added to fix the legacy file listing issue
  1308. var fd = sourceURL.split("=");
  1309. var rootPath = fd.shift();
  1310. var filename = fd.join("=");
  1311. var playbackURL = "../" + rootPath + "=" + encodeURIComponent(filename); //Convert absolute dir to relative
  1312. //console.log(playbackURL);
  1313. $("#mainAudioPlayer").attr("src", playbackURL);
  1314. audio[0].pause();
  1315. audio[0].load();
  1316. if(playAfterLoad){
  1317. audio[0].oncanplaythrough = audio[0].play();
  1318. }else{
  1319. var currentTime = audioElement[0].currentTime;
  1320. var duration = audioElement[0].duration;
  1321. $('#audioProgressBar').css('width','0%');
  1322. updatePlaybackDisplayTime(currentTime,duration);
  1323. }
  1324. loadThumbnail(sourceURL);
  1325. }
  1326. function updateMiniPlayerUI(displayName, fileinfo,id){
  1327. $("#miniPlayerDisplayName").text(displayName);
  1328. $("#miniPlayerInformation").text(fileinfo);
  1329. $("#miniPlayerIDtab").text(id + "/" + totalMusicCount);
  1330. }
  1331. function updateMainPlayerUI(songname, fileinfo, id, filepath){
  1332. $("#mainPlayerSongTitle").text(songname);
  1333. $("#mainPlayerSongDesc").text(fileinfo);
  1334. $("#mainPlayerMiniTab").text(id + "/" + totalMusicCount);
  1335. if ('mediaSession' in navigator){
  1336. var infoRewrite = fileinfo.split(" / ")
  1337. updateTitle(songname, infoRewrite[1] + " (" + infoRewrite[0] + ")", id + "/" + totalMusicCount, filepath);
  1338. }
  1339. }
  1340. /*
  1341. Playlist related functions
  1342. */
  1343. function renderPlaylistByName(listname){
  1344. $("#interfaceTitle").text(listname);
  1345. ao_module_agirun("Music/functions/playlist.js", {
  1346. opr: "list",
  1347. playlistname: listname
  1348. }, function(data){
  1349. $("#mainList").html("");
  1350. if (data.error !== undefined){
  1351. //This playlist no longer exists. Back to main
  1352. loadPlaylistView();
  1353. }else{
  1354. //Updat ethe global values
  1355. displayList = data;
  1356. totalMusicCount = data.length;
  1357. currentPath = listname;
  1358. //Add the back btn for back to playlist view
  1359. $("#mainList").append(`<div class="mainList item extrapadding" onClick="loadPlaylistView();">
  1360. <div class="ui header selectable" style="margin:0px !important;">
  1361. <i class="angle left icon whiteFont" style="overflow:hidden;"></i>
  1362. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%;">
  1363. ../
  1364. </div>
  1365. </div>
  1366. </div>`);
  1367. //List the resulting song list
  1368. for (var i = 0; i < data.length; i++){
  1369. var songInfo = data[i];
  1370. $("#mainList").append(`<div class="mainList file item" filepath=${ao_module_utils.objectToAttr(songInfo[0])} id=${i+1} rawname=${ao_module_utils.objectToAttr(songInfo[1])}>
  1371. <div class="ui header selectable" style="margin:0px !important;" onClick="playSong(this);">
  1372. <img class="ui small image" src="img/eq.svg" style="margin-right: 0.2em;"></img>
  1373. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%; font-weight: lighter;">
  1374. ${songInfo[1]}
  1375. <div class="sub header fileinfo" style="color: #c7c7c7;">${songInfo[2]} / ${songInfo[3]}</div>
  1376. </div>
  1377. </div>\
  1378. <div class="topRightCorner" align="center">
  1379. ${i + 1}
  1380. </div>
  1381. <div class="mainList rightFunctionBar" type="file" align="center" onclick="showMore(this);">
  1382. <i class="ellipsis vertical icon" style="margin-top:1.2em;"></i>
  1383. </div>
  1384. </div>`);
  1385. //Update the interface Detail
  1386. $("#interfaceDetails").text("[" + data.length + " files]");
  1387. };
  1388. loadThumbnailToMusicList();
  1389. //Fix some legacy css isseus
  1390. $("#mainList").append("<br><br><br><br><br><br><br>");
  1391. }
  1392. });
  1393. }
  1394. //Open a given playlist
  1395. function openPlaylist(object){
  1396. var listname = $(object).attr("listname");
  1397. renderPlaylistByName(listname);
  1398. }
  1399. function addToNewPlaylist(){
  1400. var playlistname = prompt("Enter new playlist name");
  1401. if (playlistname != null && playlistname != ""){
  1402. //Add to playlist
  1403. addSongToPlayList(playlistname);
  1404. }else{
  1405. $("#succSnackBar").find(".content").html(`<i class="remove icon"></i> Invalid playlist name`);
  1406. $("#succSnackBar").slideDown("fast").delay(3000).slideUp("fast");
  1407. }
  1408. }
  1409. function addToPlaylistFromMoreMenu(){
  1410. $(".showMoreMenus").fadeOut('fast');
  1411. $("#showmoreUIcover").fadeOut('fast');
  1412. showPlaylistInterface();
  1413. }
  1414. //Remove the curernt file from the current playlist
  1415. function removeFromPlylistFromMoreMenu(){
  1416. if (currentMode == "playlist"){
  1417. //Remvoe the playlistAddPendingFile
  1418. //In playlist mode, the currentPath is used to store the plylist name
  1419. ao_module_agirun("Music/functions/playlist.js", {
  1420. opr: "remove",
  1421. playlistname: currentPath,
  1422. musicpath: playlistAddPendingFile.replace("/media?file=","")
  1423. }, function(data){
  1424. if (data.error !== undefined){
  1425. alert(data.error);
  1426. }else{
  1427. //Removed. Reload playlist
  1428. renderPlaylistByName(currentPath);
  1429. //Hide the MoreMenu
  1430. hideShowMoreMenu();
  1431. }
  1432. });
  1433. }
  1434. }
  1435. function addSongToSelectedPlaylist(object){
  1436. var playlistName = $(object).attr("name").trim();
  1437. addSongToPlayList(playlistName);
  1438. }
  1439. function addSongToPlayList(listname){
  1440. //Get current music file name
  1441. var currentSongPath = "";
  1442. if (playlistAddPendingFile !== ""){
  1443. currentSongPath = playlistAddPendingFile.replace("/media?file=","");
  1444. }else{
  1445. $("#succSnackBar").find(".content").html(`<i class="remove icon"></i> No song selected`);
  1446. $("#succSnackBar").slideDown("fast").delay(3000).slideUp("fast");
  1447. return;
  1448. }
  1449. //Add to playlist
  1450. ao_module_agirun("Music/functions/playlist.js", {
  1451. opr: "add",
  1452. playlistname: listname,
  1453. musicpath: currentSongPath
  1454. },function(data){
  1455. //Show success
  1456. $("#succSnackBar").find(".content").html(`<i class="checkmark icon"></i> Added to playlist ${listname}`);
  1457. $("#succSnackBar").slideDown("fast").delay(3000).slideUp("fast");
  1458. //Reload the playlist
  1459. initPlaylistInterfaceList();
  1460. });
  1461. }
  1462. //List the number of playlist stored in this database
  1463. function loadPlaylistView(){
  1464. currentMode = "playlist";
  1465. //Clear the main list
  1466. $("#mainList").html("");
  1467. togglePagingMode(false);
  1468. ao_module_agirun("Music/functions/playlist.js", {
  1469. opr: "root",
  1470. },function(data){
  1471. //Get the list of playlist
  1472. console.log(data);
  1473. //Render the elements
  1474. data.forEach(playlist => {
  1475. $("#mainList").append(`<div class="mainList item" listname="${playlist.name}" tag="playlist" onClick="openPlaylist(this);">
  1476. <div class="ui header selectable" style="margin:0px !important;" >
  1477. <img class="ui small image" src="img/list.svg" style="margin-right: 0.2em;"></img>
  1478. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%;">
  1479. ${playlist.name}
  1480. <div class="sub header fileinfo" style="color: #c7c7c7;">[${playlist.count} files]</div>
  1481. </div>
  1482. </div>
  1483. <div class="mainList rightFunctionBar" tag="moreInfo" align="center" onClick="openPlaylist(this);">
  1484. <i class="chevron right icon" style="margin-top:1.2em;"></i>
  1485. </div>
  1486. </div>`);
  1487. });
  1488. hideLeftMenu();
  1489. //Update the headers
  1490. $("#interfaceTitle").text("Playlist");
  1491. $("#AMmenuIcon").attr("class","list icon large whiteFont");
  1492. $("#interfaceDetails").text("[" + data.length + " playlist]");
  1493. });
  1494. }
  1495. function loadFolderView(){
  1496. currentMode = "folder";
  1497. currentPath = "";
  1498. var tempalte = '<div class="mainList item" filepath={filepath} id={id} tag="folder" onClick="openFolder(this);">\
  1499. <div class="ui header selectable" style="margin:0px !important;" >\
  1500. <img class="ui small image" src="img/fo.svg" style="margin-right: 0.2em;"></img>\
  1501. <div class="content whiteFont" style="padding-top: 2px; line-height:1em;width : 80%; font-weight: lighter;">\
  1502. {foldername}\
  1503. <div class="sub header fileinfo" style="color: #c7c7c7;">{fileinfo}</div>\
  1504. </div>\
  1505. </div>\
  1506. <div class="mainList rightFunctionBar" tag="moreInfo" align="center" onClick="moreFolder(this);">\
  1507. <i class="chevron right icon" style="margin-top:1.2em;"></i>\
  1508. </div>\
  1509. </div>';
  1510. $("#interfaceTitle").text("Storage");
  1511. togglePagingMode(false);
  1512. $("#AMmenuIcon").attr("class","folder open icon large whiteFont");
  1513. ao_module_agirun("Music/functions/listSong.js", {
  1514. listdir: "root",
  1515. },function(data){
  1516. $("#mainList").html("");
  1517. for (var i =0; i < data.length; i++){
  1518. var folderName = data[i][0];
  1519. var folderPath = data[i][1];
  1520. var fileCount = data[i][2];
  1521. var folderCount = data[i][3];
  1522. var box = tempalte;
  1523. box = replaceAll("{filepath}",folderPath,box);
  1524. box = replaceAll("{id}",i + 1,box);
  1525. if (folderName == ".cache" || folderName == ".trash"){
  1526. //Hidden folders
  1527. continue;
  1528. }
  1529. if (folderPath.includes("/media")){
  1530. //This is from external storage devices. List its number as well.
  1531. var tmp = folderPath.split("/");
  1532. var extStoragePath = "/" + tmp[1] + "/" + tmp[2];
  1533. box = replaceAll("{foldername}",folderName + " ( " + extStoragePath + " )",box);
  1534. }else{
  1535. //This is directory inside normal folders.
  1536. box = replaceAll("{foldername}",folderName,box);
  1537. }
  1538. var fileinfo = "[" + fileCount + " files]"
  1539. if (folderCount > 0){
  1540. fileinfo = "[" + fileCount + " files, " + folderCount +" folders]"
  1541. }
  1542. box = replaceAll("{fileinfo}",fileinfo,box);
  1543. rootPaths.push(folderPath);
  1544. $("#mainList").append(box);
  1545. }
  1546. $("#interfaceDetails").text("[" + data.length + " folders]");
  1547. });
  1548. hideLeftMenu();
  1549. }
  1550. function isMobile(){
  1551. if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
  1552. return true
  1553. }
  1554. return false
  1555. }
  1556. function setWindowHash(hashValue){
  1557. hashValue = JSON.stringify(hashValue);
  1558. if (!isAndroid){
  1559. return;
  1560. }
  1561. if(history.pushState) {
  1562. window.history.pushState(null, null, '#' + hashValue);
  1563. }else {
  1564. location.hash = '#' + hashValue;
  1565. }
  1566. if(ao_module_virtualDesktop && !isMobile()){
  1567. //Update the iframe src as well
  1568. var newsrc = window.frameElement.getAttribute("src");
  1569. if (newsrc.includes("#")){
  1570. newsrc = newsrc.split("#")
  1571. newsrc.pop();
  1572. newsrc = newsrc.join("#");
  1573. }
  1574. newsrc = newsrc + "#" + hashValue;
  1575. $(window.frameElement).attr("src",newsrc);
  1576. //console.log(window.frameElement.getAttribute("src"));
  1577. }
  1578. }
  1579. function updateStateReferingURL(){
  1580. var paused = audioElement[0].paused; //Check the current playing state of the player
  1581. setWindowHash({path: currentPath, pfp:playingFileDetail,pause:paused});
  1582. }
  1583. function openFolder(object, playParameters=null){
  1584. var playIDAfterOpen = -1;
  1585. var startPaused = false;
  1586. if (playParameters !== null){
  1587. playIDAfterOpen = playParameters.playIDAfterOpen;
  1588. startPaused = playParameters.startPaused;
  1589. }
  1590. var backbtnTemplate = '<div class="mainList item extrapadding" filepath={filepath} id={id} onClick="openFolder(this);">\
  1591. <div class="ui header selectable" style="margin:0px !important;">\
  1592. <i class="angle left icon whiteFont" style="overflow:hidden;"></i>\
  1593. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%; font-weight: lighter;">\
  1594. ../\
  1595. </div>\
  1596. </div>\
  1597. </div>';
  1598. var folderTemplate = '<div class="mainList item" filepath={filepath} tag="folder" id={id} onClick="openFolder(this);">\
  1599. <div class="ui header selectable" style="margin:0px !important;">\
  1600. <img class="ui small image" src="img/fo.svg" style="margin-right: 0.2em;"></img>\
  1601. <div class="content whiteFont" style="padding-top:2px;line-height:1em; width:80%; font-weight: lighter;">\
  1602. {foldername}\
  1603. <div class="sub header fileinfo" style="color: #c7c7c7;">{fileinfo}</div>\
  1604. </div>\
  1605. </div>\
  1606. <div class="mainList rightFunctionBar" type="folder" align="center">\
  1607. <i class="chevron right icon" style="margin-top:1.2em;"></i>\
  1608. </div>\
  1609. </div>';
  1610. var fileTemplate = `<div class="mainList file item" filepath={filepath} id={id} rawname={rawname}>\
  1611. <div class="ui header selectable" style="margin:0px !important;" onClick="playSong(this);">\
  1612. <img class="ui small image" src="img/eq.svg" style="margin-right: 0.2em;"></img>
  1613. <!-- <i class="music icon whiteFont" style="overflow:hidden;"></i> -->\
  1614. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%; font-weight: lighter;">\
  1615. {songtitle}\
  1616. <div class="sub header fileinfo" style="color: #c7c7c7;">{ext} / {size}</div>\
  1617. </div>\
  1618. </div>\
  1619. <div class="topRightCorner" align="center">\
  1620. {id}\
  1621. </div>\
  1622. <div class="mainList rightFunctionBar" type="file" align="center">\
  1623. <i class="ellipsis vertical icon" style="margin-top:1.2em;"></i>\
  1624. </div>\
  1625. </div>`;
  1626. var targetPath = decodeURIComponent($(object).attr("filepath"));
  1627. if (targetPath == "root" || targetPath == "/"){
  1628. //User request to go back to storage root
  1629. loadFolderView();
  1630. return;
  1631. }
  1632. currentPath = targetPath.split("/./").join("/");
  1633. currentPath = currentPath.split("//").join("/");
  1634. $("#interfaceTitle").text(ao_module_codec.decodeHexFoldername(targetPath.substring(0,targetPath.length -1).split("/").pop()));
  1635. var parentDir = currentPath.split("/");
  1636. parentDir.pop();parentDir.pop();
  1637. parentDir = (parentDir.join("/") + "/");
  1638. //console.log(currentPath);
  1639. var backbtn;
  1640. if (rootPaths.includes(currentPath) == false){
  1641. //We are currently not at root
  1642. backbtn = backbtnTemplate;
  1643. backbtn = replaceAll("{filepath}",encodeURIComponent(parentDir),backbtn);
  1644. backbtn = replaceAll("{id}",0,backbtn);
  1645. }else{
  1646. //Create a back button to go back to root of storage
  1647. backbtn = backbtnTemplate;
  1648. backbtn = replaceAll("{filepath}","root",backbtn);
  1649. backbtn = replaceAll("{id}",0,backbtn);
  1650. }
  1651. //Request the server for a list of folders and file in this directory
  1652. ao_module_agirun("Music/functions/listSong.js", {
  1653. listdir: targetPath.split("//").join("/"),
  1654. },function(data){
  1655. $("#mainList").html("");
  1656. $("#mainList").append(backbtn);
  1657. if (Array.isArray(data)){
  1658. var folders = data[0];
  1659. var files = data[1];
  1660. //List all folders
  1661. for (var i =0; i < folders.length; i++){
  1662. var folderName = folders[i][0];
  1663. var folderPath = folders[i][1];
  1664. var fileCount = folders[i][2];
  1665. var folderCount = folders[i][3];
  1666. var box = folderTemplate;
  1667. if (folderName == ".cache" || folderName == ".trash"){
  1668. //Hidden folders
  1669. continue;
  1670. }
  1671. box = replaceAll("{filepath}",encodeURIComponent(folderPath),box);
  1672. box = replaceAll("{id}","folder-" + i + 1,box);
  1673. box = replaceAll("{foldername}",ao_module_codec.decodeHexFoldername(folderName),box);
  1674. var fileinfo = "[" + fileCount + " files]"
  1675. if (folderCount > 0){
  1676. fileinfo = "[" + fileCount + " files, " + folderCount +" folders]"
  1677. }
  1678. box = replaceAll("{fileinfo}",fileinfo,box);
  1679. $("#mainList").append(box);
  1680. }
  1681. //List all files
  1682. for ( var i =0; i < files.length; i++){
  1683. var songInfo = files[i];
  1684. var path = songInfo[0];
  1685. var displayname = ao_module_codec.decodeUmFilename(songInfo[1]);
  1686. var ext = songInfo[2];
  1687. var size = songInfo[3];
  1688. var box = fileTemplate;
  1689. box = replaceAll("{filepath}",ao_module_utils.objectToAttr(path),box);
  1690. box = replaceAll("{id}",i + 1,box); //User count from 1
  1691. box = replaceAll("{rawname}",ao_module_utils.objectToAttr(songInfo[1]),box);
  1692. box = replaceAll("{songtitle}",displayname,box);
  1693. box = replaceAll("{ext}",ext,box);
  1694. box = replaceAll("{size}",size,box);
  1695. $("#mainList").append(box);
  1696. }
  1697. displayList = files;
  1698. totalMusicCount = files.length;
  1699. $("#mainList").append("<br><br><br><br><br><br><br>");
  1700. }else{
  1701. //Something went wrong
  1702. //console.log('[AirMusic] Something went wrong: ' + data);
  1703. loadFolderView();
  1704. return;
  1705. }
  1706. if (folders.length > 0 && files.length > 0){
  1707. $("#interfaceDetails").text("[" + files.length + " files, " + folders.length+ " folders]");
  1708. }else if (folders.length > 0){
  1709. $("#interfaceDetails").text("[" + folders.length + " folders]");
  1710. }else if (files.length > 0){
  1711. $("#interfaceDetails").text("[" + files.length + " files]");
  1712. }else{
  1713. $("#interfaceDetails").text("[0 files or folders]");
  1714. }
  1715. //Hook all the events for the moreinfo on folders
  1716. hookMoreFolderInfoClickEvent();
  1717. //Check if the current playing file is located inside this list.
  1718. highLightPlayingMusic();
  1719. //Check if auto playback is required. If yes, play it with the given filepath.
  1720. if (playIDAfterOpen != -1){
  1721. $(".mainList.item").each(function(){
  1722. if ($(this).attr("id") == playIDAfterOpen){
  1723. //This is the file that require to playback after the folder loaded
  1724. playSong($(this).find(".ts.header.selectable"),startPaused);
  1725. setTimeout(resizeQuickAdjust,500);
  1726. }
  1727. });
  1728. }
  1729. //Load thumbnail for song in list
  1730. loadThumbnailToMusicList();
  1731. });
  1732. }
  1733. function moreInfo(object){
  1734. if ($(object).parent().attr('tag') == "folder"){
  1735. //This is a folder. Ask if play as playlist
  1736. alert("Folder playback work in progress");
  1737. }else{
  1738. showMore(object);
  1739. }
  1740. }
  1741. function hookMoreFolderInfoClickEvent(){
  1742. $(".mainList.rightFunctionBar").on("click", function(e){
  1743. e.stopPropagation();
  1744. moreInfo(this);
  1745. });
  1746. }
  1747. function highLightPlayingMusic(){
  1748. //This function is used for highlighting the current playing music if the music piece is found inside the current list
  1749. $(".mainList.item").removeClass("playingTrack");
  1750. $(".mainList.item").each(function(){
  1751. var id = parseInt($(this).attr("id"));
  1752. try{
  1753. var filepath = ao_module_utils.attrToObject($(this).attr("filepath"));
  1754. }catch{
  1755. //Use back the previous method of filepath storage for compatibility
  1756. var filepath = $(this).attr("filepath");
  1757. }
  1758. //Id is ignored in the 9/9/2019 updates and only check if the path matches.
  1759. if (filepath == playingFileDetail[1]){
  1760. $(this).addClass("playingTrack");
  1761. }
  1762. //console.log([id,filepath], playingFileDetail);
  1763. });
  1764. //Update dropdownList as well if exists
  1765. $(".dropdownList.item").removeClass("playingTrack");
  1766. $(".dropdownList.item").each(function(){
  1767. try{
  1768. var filepath = ao_module_utils.attrToObject($(this).attr("filepath"));
  1769. }catch{
  1770. //Use back the previous method of filepath storage for compatibility
  1771. var filepath = $(this).attr("filepath");
  1772. }
  1773. //var filepath = $(this).attr("filepath");
  1774. if (filepath == playingFileDetail[1]){
  1775. $(this).addClass("playingTrack");
  1776. }
  1777. });
  1778. }
  1779. function monitorFileChangeForUpload(){
  1780. if ($("#interfaceTitle").text() == "Upload"){
  1781. //It is still in upload Mode. Continue monitor file change and move them if needed
  1782. $.post("listenUploadChange.php",{fileList: JSON.stringify(currentUploadTargetFileList),directory: currentUploadTargetFilepath}).done(function(data){
  1783. if (data.includes("ERROR")){
  1784. console.log(data);
  1785. }
  1786. });
  1787. setTimeout(monitorFileChangeForUpload,1000);
  1788. }
  1789. }
  1790. function hideShowMoreMenu(){
  1791. $(".showMoreMenus").fadeOut('fast');
  1792. $("#showmoreUIcover").fadeOut('fast');
  1793. //Return the playlistAddPendingFile object back to the playing one
  1794. if (playingFileDetail !== undefined){
  1795. playlistAddPendingFile = playingFileDetail[1];
  1796. }else{
  1797. //No song is being play back
  1798. playlistAddPendingFile = "";
  1799. }
  1800. }
  1801. function playFromShowMoreMenu(){
  1802. nextSong(showMoreOprPlayID - 1);
  1803. $(".showMoreMenus").fadeOut('fast');
  1804. }
  1805. function showFileInfo(){
  1806. $("#showFileInfo").show();
  1807. $("#showMoreUI").hide();
  1808. }
  1809. function startRelatedSearch(){
  1810. enterSearchMode();
  1811. $("#searchInputBar").val(showMoreoprDisplayName);
  1812. $("#searchInputBar").focus();
  1813. hideShowMoreMenu();
  1814. }
  1815. function searchYoutubeViaShowMore(){
  1816. if (showMoreoprDisplayName != "" || showMoreoprDisplayName != undefined){
  1817. var filename = showMoreoprDisplayName;
  1818. searchOnYoutube(filename);
  1819. }
  1820. }
  1821. var showMoreOprPlayID,showMoreOprFilepath, showMoreoprDisplayName;
  1822. function showMore(object){
  1823. var filepath = $(object).parent().attr("filepath");
  1824. filepath = JSON.parse(decodeURIComponent(filepath));
  1825. //User want more action on this file. assume this is the file to add
  1826. playlistAddPendingFile = filepath;
  1827. var id = $(object).parent().attr('id');
  1828. var rawname = $(object).parent().attr("rawname");
  1829. var displayName = JSON.parse(decodeURIComponent(ao_module_codec.decodeUmFilename(rawname)));
  1830. //Update global variable for quick operations
  1831. showMoreOprPlayID = id;
  1832. showMoreOprFilepath = filepath;
  1833. showMoreoprDisplayName = displayName;
  1834. $("#showMoreUI").find(".songTitle").text(displayName);
  1835. $("#showMoreUI").find(".songID").text(id);
  1836. $("#showFileInfo").find(".songTitle").text(displayName);
  1837. $("#showMoreUI").fadeIn('fast');
  1838. $("#showmoreUIcover").fadeIn('fast');
  1839. //Update fileinformation as well
  1840. if (filepath.substring(0, 12) == "/media?file="){
  1841. filepath = filepath.substring(12);
  1842. }
  1843. //Pre-render the file info
  1844. ao_module_agirun("Music/functions/getFileInfo.js", {
  1845. filepath: filepath,
  1846. }, function(data){
  1847. $("#showFileInfo").find(".filename").text(ao_module_codec.decodeUmFilename(data[0]));
  1848. $("#showFileInfo").find(".rawname").text(data[0]);
  1849. $("#showFileInfo").find(".filepath").text(data[1]);
  1850. $("#showFileInfo").find(".filesize").text(data[2] + " (" + data[3] + " Bytes)");
  1851. $("#showFileInfo").find(".filedate").text(data[4]);
  1852. });
  1853. if (currentMode != "playlist"){
  1854. $(".playlistonly").hide();
  1855. }else{
  1856. $(".playlistonly").show();
  1857. }
  1858. }
  1859. function playSongFromDropdownList(object){
  1860. //Play song from dropdown list. Hence, no need to update dropdownList
  1861. if ($(object).parent().hasClass("playingTrack")){
  1862. //This song already playing. Ignore play request.
  1863. return;
  1864. }
  1865. playSong(object);
  1866. //Check if the song is also in main list. If yes, highlight it as well
  1867. /*
  1868. $(".mainList.item").each(function(){
  1869. if ($(this).attr("filepath") == $(object).parent().attr("filepath")){
  1870. $(".mainList.item.playingTrack").removeClass("playingTrack");
  1871. $(this).addClass("playingTrack");
  1872. }
  1873. });
  1874. */
  1875. $("#dropdownSonglist").delay(500).slideUp();
  1876. highLightPlayingMusic();
  1877. }
  1878. //Move the playing song list into the dropdown song list. This list might not be the same as the one in the main list.
  1879. function parsePlayingSongList(){
  1880. $("#currentPlayingMainList").html("");
  1881. var counter = playingList.length;
  1882. var totalSize = 0.0;
  1883. var renderRange = [0, playingList.length];
  1884. if (pagingEnabled){
  1885. //Paging Enabled. Only show 1/2 max + current page song + 1/2 max
  1886. var startEndRange = getPageStartAndEndByPageNumber(currentPage);
  1887. startEndRange = [startEndRange[0] - pagingCutoffCount /2, startEndRange[1] + pagingCutoffCount / 2]
  1888. if (startEndRange[0] < 0){
  1889. startEndRange[0] = 0;
  1890. }
  1891. if (startEndRange[1] > playingList.length){
  1892. startEndRange[1] = playingList.length;
  1893. }
  1894. renderRange = startEndRange;
  1895. }
  1896. for (var i = renderRange[0]; i < renderRange[1]; i++){
  1897. var displayname = ao_module_codec.decodeUmFilename(playingList[i][1]);
  1898. if (playingList[i][3].includes("MB")){
  1899. totalSize += parseFloat(playingList[i][3].split(" ")[0]);
  1900. }else if (playingList[i][3].includes("KB")){
  1901. totalSize += parseFloat(playingList[i][3].split(" ")[0]) / 1000;
  1902. }else if (playingList[i][3].includes("GB")){
  1903. totalSize += parseFloat(playingList[i][3].split(" ")[0]) * 1000;
  1904. }
  1905. //Get thumbnail from the current list to prevent re-loading form remote
  1906. let targetThumbnail = $("#" + (i + 1)).find("img").attr("src");
  1907. let opacityShowing = "";
  1908. if ($("#" + (i + 1)).length == 0){
  1909. //Item not exists
  1910. targetThumbnail = "img/eq.svg";
  1911. opacityShowing = "opacity: 0.6;"
  1912. }
  1913. $("#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])}">
  1914. <div class="ui header selectable" style="margin:0px !important;" onClick="playSongFromDropdownList(this);">
  1915. <img class="ui small image" src="${targetThumbnail}" style="margin-right: 0.2em;"></img>
  1916. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%;">
  1917. <span style="font-weight: lighter;">${displayname}</span>
  1918. <div class="sub header fileinfo" style="color: #c7c7c7;">${playingList[i][2]} / ${playingList[i][3]}</div>
  1919. </div>
  1920. </div>
  1921. <div class="topRightCorner" align="center">
  1922. ${i + 1}
  1923. </div>
  1924. </div>`);
  1925. $("#dropdownListSongCount").text(counter);
  1926. $("#dropdownListIDCount").text(parseInt(totalSize) + "");
  1927. }
  1928. $(".dropdownList.item").each(function(){
  1929. if ($(this).attr('filepath') == playingFileDetail[1]){
  1930. $(this).addClass("playingTrack");
  1931. }
  1932. });
  1933. }
  1934. function loadSongList(type = "all"){
  1935. currentPath = "";
  1936. currentMode = "music";
  1937. $("#interfaceTitle").text("Music");
  1938. $("#AMmenuIcon").attr("class","music icon large whiteFont")
  1939. ao_module_agirun("Music/functions/listSong.js", {
  1940. listSong: type,
  1941. },function(data){
  1942. //Initialize the song list
  1943. displayList = data;
  1944. if (type == "all"){
  1945. //Caching is used in here
  1946. displayList = data.list;
  1947. if (data.cached == true){
  1948. //This is a cached version of the music list.
  1949. console.log("Updating cached song list");
  1950. ao_module_agirun("Music/functions/buildCache.js", {}, function(data){
  1951. console.log("Cache updated: ", data);
  1952. });
  1953. }
  1954. }
  1955. //Updates 2022-07-12: Check if the list is too long. If yes, use paging
  1956. let renderRange = [0,displayList.length];
  1957. if (displayList.length > pagingCutoffCount){
  1958. togglePagingMode(true);
  1959. renderRange = [0, pagingCutoffCount];
  1960. }else{
  1961. togglePagingMode(false);
  1962. }
  1963. if (playingList == []){
  1964. playingList = Array.from(displayList);
  1965. }
  1966. renderDisplayList(displayList,renderRange[0], renderRange[1] );
  1967. }, function(){
  1968. alert("Failed to access listSong API with type: " + type)
  1969. });
  1970. hideLeftMenu();
  1971. }
  1972. function renderDisplayList(displayList, start, end, callback=undefined){
  1973. $("#mainList").html("");
  1974. for ( var i =start; i < end; i++){
  1975. var songInfo = displayList[i];
  1976. var path = songInfo[0];
  1977. var displayname = ao_module_codec.decodeUmFilename(songInfo[1]);
  1978. var ext = songInfo[2];
  1979. var size = songInfo[3];
  1980. $("#mainList").append(`<div class="mainList file item" filepath="${ao_module_utils.objectToAttr(path)}" id="${i + 1}" rawname="${ao_module_utils.objectToAttr(songInfo[1])}">
  1981. <div class="ui header selectable" style="margin:0px !important;" onClick="playSong(this);">
  1982. <img class="ui small image" src="img/eq.svg" style="margin-right: 0.2em;"></img>
  1983. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%; font-weight: lighter;">
  1984. ${displayname}
  1985. <div class="sub header fileinfo" style="color: #c7c7c7;">${ext} / ${size}</div>
  1986. </div>
  1987. </div>
  1988. <div class="topRightCorner" align="center">
  1989. ${i + 1}
  1990. </div>
  1991. <div class="mainList rightFunctionBar" align="center" onClick="showMore(this);">
  1992. <i class="ellipsis vertical icon" style="margin-top:1.2em;"></i>\
  1993. </div>
  1994. </div>`);
  1995. }
  1996. if (pagingEnabled){
  1997. //Append the page switch buttons
  1998. let numberOfPages = Math.ceil(parseFloat(displayList.length) / parseFloat(pagingCutoffCount));
  1999. let pageSelector = "";
  2000. for (var i = 0; i < numberOfPages; i++){
  2001. pageSelector = pageSelector + `<button onclick="switchToPage(${i});" class="inverted ui icon button" style="border: 0px solid transparent; box-shadow: none !important; -webkit-box-shadow: none !important;">
  2002. ${i + 1}
  2003. </button>`;
  2004. }
  2005. $("#mainList").append(`<div class="mainList item" style="cursor: unset;">
  2006. <div>${pageSelector}</div>
  2007. </div>`);
  2008. }
  2009. totalMusicCount = displayList.length;
  2010. $("#mainList").append("<br><br><br><br><br><br><br>");
  2011. $("#interfaceDetails").text("[" + totalMusicCount + " songs]");
  2012. highLightPlayingMusic();
  2013. //Load thumbnail for song in list
  2014. loadThumbnailToMusicList();
  2015. if (callback != undefined){
  2016. callback();
  2017. }
  2018. }
  2019. function switchToPage(pageNumber, callback=undefined){
  2020. if (!pagingEnabled){
  2021. return;
  2022. }
  2023. let thisCallback = callback;
  2024. if (pageNumber == currentPage){
  2025. //Already in that page
  2026. if (thisCallback != undefined){
  2027. callback();
  2028. }
  2029. return;
  2030. }
  2031. currentPage = pageNumber;
  2032. let startPage = pageNumber * pagingCutoffCount;
  2033. let endPage = startPage + pagingCutoffCount;
  2034. if (endPage > displayList.length){
  2035. endPage = displayList.length;
  2036. }
  2037. if (thisCallback == undefined){
  2038. renderDisplayList(displayList, startPage, endPage, function(){
  2039. window.scrollTo(0, document.body.scrollHeight);
  2040. });
  2041. }else{
  2042. renderDisplayList(displayList, startPage, endPage,thisCallback);
  2043. }
  2044. }
  2045. function getPageNumberByPlaybackId(id){
  2046. let numberOfPages = Math.ceil(parseFloat(displayList.length) / parseFloat(pagingCutoffCount));
  2047. let targetPageNo = Math.ceil(id / pagingCutoffCount) - 1;
  2048. return targetPageNo;
  2049. }
  2050. function getPageStartAndEndByPageNumber(pageNumber){
  2051. let startPage = pageNumber * pagingCutoffCount;
  2052. let endPage = startPage + pagingCutoffCount;
  2053. if (endPage > displayList.length){
  2054. endPage = displayList.length;
  2055. }
  2056. return [startPage, endPage];
  2057. }
  2058. function toggleLeftMenu(){
  2059. if (leftMenuShown){
  2060. $("#leftSideBar").animate({left: $("#leftSideBar").width() * -1}, 300,function(){
  2061. $("#leftSideBar").hide();
  2062. });
  2063. $("#sideBarCover").fadeOut();
  2064. leftMenuShown = false;
  2065. }else{
  2066. $("#leftSideBar").show();
  2067. $("#leftSideBar").animate({left:0}, 300);
  2068. $("#sideBarCover").fadeIn();
  2069. leftMenuShown = true;
  2070. }
  2071. }
  2072. function hideLeftMenu(){
  2073. if (leftMenuShown){
  2074. $("#leftSideBar").animate({left: $("#leftSideBar").width() * -1}, 300,function(){
  2075. $("#leftSideBar").hide();
  2076. });
  2077. $("#sideBarCover").fadeOut();
  2078. leftMenuShown = false;
  2079. }
  2080. }
  2081. function showFileInformation(){
  2082. ao_module_agirun("Music/functions/getFileInfo.js", {
  2083. filepath: playingFileDetail[1],
  2084. },function(data){
  2085. //console.log(data);
  2086. $("#settingInterface").hide();
  2087. $("#filepropInterface").show();
  2088. $("#filepropInterface").find(".filename").text(ao_module_codec.decodeUmFilename(data[0]));
  2089. $("#filepropInterface").find(".rawname").text(data[0]);
  2090. $("#filepropInterface").find(".filepath").text(data[1]);
  2091. $("#filepropInterface").find(".filesize").text(data[2] + " (" + data[3] + " Bytes)");
  2092. $("#filepropInterface").find(".filedate").text(data[4]);
  2093. });
  2094. }
  2095. function resizeQuickAdjust(){
  2096. //Resize the position of the leftMenu
  2097. if (!leftMenuShown){
  2098. $("#leftSideBar").css("left", $("#leftSideBar").width() * -1);
  2099. }
  2100. if ($("#playerInterface").offset().left != 0){
  2101. $("#playerInterface").css("left",window.innerWidth);
  2102. }
  2103. $("#albumnArtImage").css("max-height",window.innerHeight - 255);
  2104. setTimeout(function(){
  2105. $("#albumnArt").css({
  2106. "height": window.innerHeight - 255,
  2107. "top": (window.innerHeight / 2 - $("#albumnArtImage").height()/2)
  2108. });
  2109. },50);
  2110. //var imageTop = (window.innerHeight - 255 - $("#albumnArtImage").height()) / 2;
  2111. //$("#albumnArtImage").css("top",imageTop + "px");
  2112. }
  2113. function setStorage(configName,configValue){
  2114. ao_module_storage.setStorage("AirMusic",configName,configValue);
  2115. /*
  2116. $.ajax({
  2117. type: 'GET',
  2118. url: "../system/file_system/preference",
  2119. data: {key: "AirMusic/" + configName,value:configValue},
  2120. success: function(data){},
  2121. async:true
  2122. });
  2123. */
  2124. return true;
  2125. }
  2126. function loadStorage(configName){
  2127. /*
  2128. var result = "";
  2129. $.ajax({
  2130. type: 'GET',
  2131. url: "../system/file_system/preference",
  2132. data: {key: "AirMusic/" + configName},
  2133. success: function(data){
  2134. if (data.error !== undefined){
  2135. result = "";
  2136. }else{
  2137. result = data;
  2138. }
  2139. },
  2140. error: function(data){result = "";},
  2141. async:false,
  2142. timeout: 3000
  2143. });
  2144. return result;
  2145. */
  2146. return ao_module_storage.loadStorage("AirMusic",configName);
  2147. }
  2148. //Wipe controller for mobile users
  2149. $("#albumnArt")[0].addEventListener('touchstart', handleTouchStart, false);
  2150. $("#albumnArt")[0].addEventListener('touchmove', handleTouchMove, false);
  2151. var xDown = null;
  2152. var yDown = null;
  2153. function getTouches(evt) {
  2154. return evt.touches || // browser API
  2155. evt.originalEvent.touches; // jQuery
  2156. }
  2157. function handleTouchStart(evt) {
  2158. const firstTouch = getTouches(evt)[0];
  2159. xDown = firstTouch.clientX;
  2160. yDown = firstTouch.clientY;
  2161. };
  2162. function handleTouchMove(evt) {
  2163. if ( ! xDown || ! yDown ) {
  2164. return;
  2165. }
  2166. var xUp = evt.touches[0].clientX;
  2167. var yUp = evt.touches[0].clientY;
  2168. var xDiff = xDown - xUp;
  2169. var yDiff = yDown - yUp;
  2170. if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) {/*most significant*/
  2171. if ( xDiff > 0 ) {
  2172. /* left swipe */
  2173. //Going to the next song
  2174. nextSong();
  2175. } else {
  2176. /* right swipe */
  2177. //Going back one song
  2178. previousSong();
  2179. }
  2180. } else {
  2181. if ( yDiff > 0 ) {
  2182. /* up swipe */
  2183. } else {
  2184. /* down swipe */
  2185. }
  2186. }
  2187. /* reset values */
  2188. xDown = null;
  2189. yDown = null;
  2190. };
  2191. //Handle audio progress to time conversion
  2192. function secondsToHms(d) {
  2193. d = Number(d);
  2194. var h = Math.floor(d / 3600);
  2195. var m = Math.floor(d % 3600 / 60);
  2196. var s = Math.floor(d % 3600 % 60);
  2197. if (h > 0 && h < 10){
  2198. dh = "0" + h + ":";
  2199. }else if (h == 0){
  2200. dh = "";
  2201. }else{
  2202. dh = h + ":";
  2203. }
  2204. if (m > 0 && m < 10){
  2205. dm = "0" + m + ":";
  2206. }else if (m == 0){
  2207. if (h > 0){
  2208. dm = "00:";
  2209. }else{
  2210. dm = "0:";
  2211. }
  2212. }else{
  2213. dm = m + ":";
  2214. }
  2215. if (s > 0 && s < 10){
  2216. ds = "0" + s;
  2217. }else if (s == 0){
  2218. if (m > 0 || h > 0){
  2219. ds = "00";
  2220. }else{
  2221. ds = "00";
  2222. }
  2223. }else{
  2224. ds = s;
  2225. }
  2226. return dh + dm + ds;
  2227. }
  2228. //Handle window resize events
  2229. $(window).on("resize", function(){
  2230. resizeQuickAdjust();
  2231. });
  2232. function AllQuickMenuHidden(){
  2233. var result = true;
  2234. $(".quickMenu").each(function(){
  2235. if ( $(this).is(':visible') ){
  2236. result = false;
  2237. }
  2238. });
  2239. return result;
  2240. }
  2241. function AllSubMenuHidden(){
  2242. var result = true;
  2243. $(".showMoreMenus").each(function(){
  2244. if ( $(this).is(':visible') ){
  2245. result = false;
  2246. }
  2247. });
  2248. return result;
  2249. }
  2250. //Handle back button press on mobile devices
  2251. function handleBackButton() {
  2252. if (!AllQuickMenuHidden()){
  2253. hideAllquickMenu();
  2254. window.history.pushState({}, '');
  2255. }else if (mainPlayerShown()){
  2256. //Close the main Menu
  2257. hideMainPlayerInterface();
  2258. window.history.pushState({}, '');
  2259. }else if (!AllSubMenuHidden()){
  2260. $(".showMoreMenus").fadeOut('fast');
  2261. $("#showmoreUIcover").fadeOut('fast');
  2262. window.history.pushState({}, '');
  2263. }else{
  2264. window.history.back();
  2265. }
  2266. }
  2267. window.addEventListener('popstate', handleBackButton);
  2268. window.history.pushState({}, '');
  2269. </script>
  2270. </body>
  2271. </html>