index.html 87 KB

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