index.html 92 KB

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