index.html 86 KB

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