index.html 85 KB

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