index.html 84 KB

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