index.html 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575
  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. fetch("../system/file_system/loadThumbnail?vpath=" + encodeURIComponent(realVpath))
  1106. .then((response) => response.json())
  1107. .then((data) => {
  1108. if (data.error !== undefined || data.trim() == ""){
  1109. return;
  1110. }
  1111. $("#" + thisFileItemID).find("img").attr("src","data:image/jpg;base64," + data);
  1112. $(".dropdownList.file.item").each(function(){
  1113. var thisFilepath = JSON.parse(decodeURIComponent($(this).attr("filepath")));
  1114. if ($(this).attr("listid") == thisFileItemID && thisFilepath == filepath){
  1115. $(this).find("img").attr("src","data:image/jpg;base64," + data);
  1116. }
  1117. });
  1118. });
  1119. /*
  1120. ao_module_agirun("Music/functions/getThumbnail.js", {
  1121. file: realVpath,
  1122. }, function(data){
  1123. if (data.error !== undefined){
  1124. }else{
  1125. $("#" + thisFileItemID).find("img").attr("src","data:image/jpg;base64," + data);
  1126. $(".dropdownList.file.item").each(function(){
  1127. var thisFilepath = JSON.parse(decodeURIComponent($(this).attr("filepath")));
  1128. if ($(this).attr("listid") == thisFileItemID && thisFilepath == filepath){
  1129. $(this).find("img").attr("src","data:image/jpg;base64," + data);
  1130. }
  1131. })
  1132. }
  1133. });
  1134. */
  1135. })
  1136. }
  1137. function loadThumbnail(filepath){
  1138. //Load the thumbnail
  1139. var realVpath = filepath.split("=");
  1140. realVpath.shift();
  1141. realVpath = realVpath.join("=");
  1142. ao_module_agirun("Music/functions/getThumbnail.js", {
  1143. file: realVpath,
  1144. }, function(data){
  1145. if (data.error !== undefined){
  1146. console.log(data.error)
  1147. $("#albumnArtImage").attr("src","img/default.png");
  1148. $("#smallPlayerThumb").attr("src","img/default.png");
  1149. if (navigator.mediaSession.metadata){
  1150. navigator.mediaSession.metadata.artwork = [
  1151. { src: "img/default.png", sizes: '512x512', type: 'image/png' }
  1152. ]
  1153. }
  1154. }else{
  1155. $("#albumnArtImage").attr("src","data:image/jpg;base64," + data);
  1156. $("#smallPlayerThumb").attr("src","data:image/jpg;base64," + data);
  1157. if (isAndroid && navigator.mediaSession.metadata){
  1158. //Android
  1159. navigator.mediaSession.metadata.artwork = [
  1160. { src: "data:image/jpg;base64," + data, sizes: '480x480', type: 'image/jpg' }
  1161. ]
  1162. }
  1163. }
  1164. resizeQuickAdjust();
  1165. });
  1166. }
  1167. function nextSong(id = false,forcePlayEvenStopped = false){
  1168. //Check if the current playlist has more than one songs.
  1169. var currentPaused = audioElement[0].paused;
  1170. if (playingList.length > 1){
  1171. var nextSongIndex = playingFileDetail[0];
  1172. if (id != false){
  1173. //Allow manual overwrite for this function
  1174. nextSongIndex = id;
  1175. var nextSong = playingList[nextSongIndex];
  1176. }else{
  1177. if (playingFileDetail[0] >= playingList.length){
  1178. var nextSong = playingList[0]; //Back to the first song in list
  1179. nextSongIndex = 0;
  1180. }else{
  1181. var nextSong = playingList[nextSongIndex]; //Index of the playList + 1 as the index for the files is alrady i+1. (User count from one)
  1182. }
  1183. }
  1184. //The songs has to be play via background services instead of relying on DOM
  1185. var filepath = nextSong[0];
  1186. var rawname = nextSong[1];
  1187. var displayName = ao_module_codec.decodeUmFilename(rawname);
  1188. var info = nextSong[2] + " / " + nextSong[3];
  1189. var id = nextSongIndex + 1;
  1190. updateMiniPlayerUI(displayName,info,id);
  1191. //Seperate out the filepath without media server path
  1192. var fileVpath = filepath.split("=")[1];
  1193. updateMainPlayerUI(displayName,info,id, fileVpath);
  1194. if (forcePlayEvenStopped){
  1195. loadAndPlayAudioFile(filepath,true);
  1196. }else{
  1197. loadAndPlayAudioFile(filepath,!currentPaused);
  1198. }
  1199. if (currentPlaying){
  1200. setPlaying(true);
  1201. }
  1202. playingFileDetail = [id,filepath];
  1203. //Need not to update the playlist because it is the same
  1204. if (pagingEnabled){
  1205. var targetPageNumber = getPageNumberByPlaybackId(parseInt(id));
  1206. switchToPage(targetPageNumber, function(){
  1207. parsePlayingSongList();
  1208. highLightPlayingMusic();
  1209. });
  1210. }else{
  1211. highLightPlayingMusic();
  1212. }
  1213. }else{
  1214. //This is the only song in playlist. Play again from start
  1215. audioElement[0].pause();
  1216. audioElement[0].currentTime = 0;
  1217. if (!currentPaused){
  1218. audioElement[0].play();
  1219. }
  1220. }
  1221. updateStateReferingURL();
  1222. }
  1223. function previousSong(){
  1224. var currentPaused = audioElement[0].paused;
  1225. if (playingList.length > 1){
  1226. var nextSongIndex = playingFileDetail[0] - 1;
  1227. if (nextSongIndex == 0){
  1228. nextSongIndex = playingList.length;
  1229. var nextSong = playingList[nextSongIndex - 1]; //Back to the last song in list
  1230. }else{
  1231. 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)
  1232. }
  1233. //The songs has to be play via background services instead of relying on DOM
  1234. var filepath = nextSong[0];
  1235. var rawname = nextSong[1];
  1236. var displayName = ao_module_codec.decodeUmFilename(rawname);
  1237. var info = nextSong[2] + " / " + nextSong[3];
  1238. var id = nextSongIndex;
  1239. updateMiniPlayerUI(displayName,info,id);
  1240. //Seperate out the filepath without media server path
  1241. var fileVpath = filepath.split("=")[1];
  1242. updateMainPlayerUI(displayName,info,id, fileVpath);
  1243. loadAndPlayAudioFile(filepath,!currentPaused);
  1244. if (currentPlaying){
  1245. setPlaying(true);
  1246. }
  1247. playingFileDetail = [id,filepath];
  1248. //Need not to update the playlist because it is the same
  1249. if (pagingEnabled){
  1250. var targetPageNumber = getPageNumberByPlaybackId(parseInt(id));
  1251. switchToPage(targetPageNumber, function(){
  1252. parsePlayingSongList();
  1253. highLightPlayingMusic();
  1254. });
  1255. }else{
  1256. highLightPlayingMusic();
  1257. }
  1258. }else{
  1259. //This is the only song in playlist. Play again from start
  1260. audioElement[0].pause();
  1261. audioElement[0].currentTime = 0;
  1262. audioElement[0].play();
  1263. }
  1264. updateStateReferingURL();
  1265. }
  1266. var originalVol = 0;
  1267. function togglePlayMode(){
  1268. if (currentPlaying){
  1269. originalVol = audioElement[0].volume;
  1270. fadeAudio();
  1271. setPlaying(false);
  1272. }else{
  1273. gainAudio();
  1274. setPlaying(true);
  1275. }
  1276. }
  1277. let audioTransitioning = false;
  1278. function fadeAudio(){
  1279. audioTransitioning = true;
  1280. if(audioElement[0].volume > 0){
  1281. var testval = audioElement[0].volume - 0.1;
  1282. audioElement[0].volume = Math.max(0,testval);
  1283. setTimeout(fadeAudio, 50);
  1284. }else{
  1285. audioElement[0].pause();
  1286. setTimeout(function(){
  1287. audioElement[0].volume = originalVol;
  1288. updateStateReferingURL();
  1289. audioTransitioning = false;
  1290. }, 100);
  1291. }
  1292. }
  1293. var targetVol = 0;
  1294. function gainAudio(){
  1295. targetVol = audioElement[0].volume;
  1296. audioElement[0].volume = 0;
  1297. setTimeout(function(){
  1298. audioElement[0].play();
  1299. recursiveGainAudio();
  1300. }, 100);
  1301. }
  1302. function recursiveGainAudio(){
  1303. audioTransitioning = true;
  1304. if(audioElement[0].volume < targetVol){
  1305. if (audioElement[0].volume + 0.1 < 1){
  1306. audioElement[0].volume += 0.1
  1307. }else{
  1308. //Audio volume larger than 1, make it 1
  1309. audioElement[0].volume = 1
  1310. }
  1311. setTimeout(recursiveGainAudio, 50);
  1312. }else{
  1313. setTimeout(function(){
  1314. audioElement[0].volume = targetVol;
  1315. updateStateReferingURL();
  1316. audioTransitioning = false;
  1317. }, 100);
  1318. }
  1319. }
  1320. //Update all icons on play and pause buttons
  1321. function setPlaying(playing){
  1322. if (playing == true){
  1323. $(".PlayButton").attr("class","pause icon whiteFont PlayButton");
  1324. currentPlaying = true;
  1325. }else{
  1326. $(".PlayButton").attr("class","play icon whiteFont PlayButton");
  1327. currentPlaying = false;
  1328. }
  1329. }
  1330. function loadAndPlayAudioFile(sourceURL,playAfterLoad = true){
  1331. var audio = audioElement;
  1332. //These was added to fix the legacy file listing issue
  1333. var fd = sourceURL.split("=");
  1334. var rootPath = fd.shift();
  1335. var filename = fd.join("=");
  1336. var playbackURL = "../" + rootPath + "=" + encodeURIComponent(filename); //Convert absolute dir to relative
  1337. //console.log(playbackURL);
  1338. $("#mainAudioPlayer").attr("src", playbackURL);
  1339. audio[0].pause();
  1340. audio[0].load();
  1341. if(playAfterLoad){
  1342. audio[0].oncanplaythrough = audio[0].play();
  1343. }else{
  1344. var currentTime = audioElement[0].currentTime;
  1345. var duration = audioElement[0].duration;
  1346. $('#audioProgressBar').css('width','0%');
  1347. updatePlaybackDisplayTime(currentTime,duration);
  1348. }
  1349. loadThumbnail(sourceURL);
  1350. }
  1351. function updateMiniPlayerUI(displayName, fileinfo,id){
  1352. $("#miniPlayerDisplayName").text(displayName);
  1353. $("#miniPlayerInformation").text(fileinfo);
  1354. $("#miniPlayerIDtab").text(id + "/" + totalMusicCount);
  1355. }
  1356. function updateMainPlayerUI(songname, fileinfo, id, filepath){
  1357. $("#mainPlayerSongTitle").text(songname);
  1358. $("#mainPlayerSongDesc").text(fileinfo);
  1359. $("#mainPlayerMiniTab").text(id + "/" + totalMusicCount);
  1360. if ('mediaSession' in navigator){
  1361. var infoRewrite = fileinfo.split(" / ")
  1362. updateTitle(songname, infoRewrite[1] + " (" + infoRewrite[0] + ")", id + "/" + totalMusicCount, filepath);
  1363. }
  1364. }
  1365. /*
  1366. Playlist related functions
  1367. */
  1368. function renderPlaylistByName(listname){
  1369. $("#interfaceTitle").text(listname);
  1370. ao_module_agirun("Music/functions/playlist.js", {
  1371. opr: "list",
  1372. playlistname: listname
  1373. }, function(data){
  1374. $("#mainList").html("");
  1375. if (data.error !== undefined){
  1376. //This playlist no longer exists. Back to main
  1377. loadPlaylistView();
  1378. }else{
  1379. //Updat ethe global values
  1380. displayList = data;
  1381. totalMusicCount = data.length;
  1382. currentPath = listname;
  1383. //Add the back btn for back to playlist view
  1384. $("#mainList").append(`<div class="mainList item extrapadding" onClick="loadPlaylistView();">
  1385. <div class="ui header selectable" style="margin:0px !important;">
  1386. <i class="angle left icon whiteFont" style="overflow:hidden;"></i>
  1387. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%;">
  1388. ../
  1389. </div>
  1390. </div>
  1391. </div>`);
  1392. //List the resulting song list
  1393. for (var i = 0; i < data.length; i++){
  1394. var songInfo = data[i];
  1395. $("#mainList").append(`<div class="mainList file item" filepath=${ao_module_utils.objectToAttr(songInfo[0])} id=${i+1} rawname=${ao_module_utils.objectToAttr(songInfo[1])}>
  1396. <div class="ui header selectable" style="margin:0px !important;" onClick="playSong(this);">
  1397. <img class="ui small image" src="img/eq.svg" style="margin-right: 0.2em;"></img>
  1398. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%; font-weight: lighter;">
  1399. ${songInfo[1]}
  1400. <div class="sub header fileinfo" style="color: #c7c7c7;">${songInfo[2]} / ${songInfo[3]}</div>
  1401. </div>
  1402. </div>\
  1403. <div class="topRightCorner" align="center">
  1404. ${i + 1}
  1405. </div>
  1406. <div class="mainList rightFunctionBar" type="file" align="center" onclick="showMore(this);">
  1407. <i class="ellipsis vertical icon" style="margin-top:1.2em;"></i>
  1408. </div>
  1409. </div>`);
  1410. //Update the interface Detail
  1411. $("#interfaceDetails").text("[" + data.length + " files]");
  1412. };
  1413. loadThumbnailToMusicList();
  1414. //Fix some legacy css isseus
  1415. $("#mainList").append("<br><br><br><br><br><br><br>");
  1416. }
  1417. });
  1418. }
  1419. //Open a given playlist
  1420. function openPlaylist(object){
  1421. var listname = $(object).attr("listname");
  1422. renderPlaylistByName(listname);
  1423. }
  1424. function addToNewPlaylist(){
  1425. var playlistname = prompt("Enter new playlist name");
  1426. if (playlistname != null && playlistname != ""){
  1427. //Add to playlist
  1428. addSongToPlayList(playlistname);
  1429. }else{
  1430. $("#succSnackBar").find(".content").html(`<i class="remove icon"></i> Invalid playlist name`);
  1431. $("#succSnackBar").slideDown("fast").delay(3000).slideUp("fast");
  1432. }
  1433. }
  1434. function addToPlaylistFromMoreMenu(){
  1435. $(".showMoreMenus").fadeOut('fast');
  1436. $("#showmoreUIcover").fadeOut('fast');
  1437. showPlaylistInterface();
  1438. }
  1439. //Remove the curernt file from the current playlist
  1440. function removeFromPlylistFromMoreMenu(){
  1441. if (currentMode == "playlist"){
  1442. //Remvoe the playlistAddPendingFile
  1443. //In playlist mode, the currentPath is used to store the plylist name
  1444. ao_module_agirun("Music/functions/playlist.js", {
  1445. opr: "remove",
  1446. playlistname: currentPath,
  1447. musicpath: playlistAddPendingFile.replace("/media?file=","")
  1448. }, function(data){
  1449. if (data.error !== undefined){
  1450. alert(data.error);
  1451. }else{
  1452. //Removed. Reload playlist
  1453. renderPlaylistByName(currentPath);
  1454. //Hide the MoreMenu
  1455. hideShowMoreMenu();
  1456. }
  1457. });
  1458. }
  1459. }
  1460. function addSongToSelectedPlaylist(object){
  1461. var playlistName = $(object).attr("name").trim();
  1462. addSongToPlayList(playlistName);
  1463. }
  1464. function addSongToPlayList(listname){
  1465. //Get current music file name
  1466. var currentSongPath = "";
  1467. if (playlistAddPendingFile !== ""){
  1468. currentSongPath = playlistAddPendingFile.replace("/media?file=","");
  1469. }else{
  1470. $("#succSnackBar").find(".content").html(`<i class="remove icon"></i> No song selected`);
  1471. $("#succSnackBar").slideDown("fast").delay(3000).slideUp("fast");
  1472. return;
  1473. }
  1474. //Add to playlist
  1475. ao_module_agirun("Music/functions/playlist.js", {
  1476. opr: "add",
  1477. playlistname: listname,
  1478. musicpath: currentSongPath
  1479. },function(data){
  1480. //Show success
  1481. $("#succSnackBar").find(".content").html(`<i class="checkmark icon"></i> Added to playlist ${listname}`);
  1482. $("#succSnackBar").slideDown("fast").delay(3000).slideUp("fast");
  1483. //Reload the playlist
  1484. initPlaylistInterfaceList();
  1485. });
  1486. }
  1487. //List the number of playlist stored in this database
  1488. function loadPlaylistView(){
  1489. currentMode = "playlist";
  1490. //Clear the main list
  1491. $("#mainList").html("");
  1492. togglePagingMode(false);
  1493. ao_module_agirun("Music/functions/playlist.js", {
  1494. opr: "root",
  1495. },function(data){
  1496. //Get the list of playlist
  1497. console.log(data);
  1498. //Render the elements
  1499. data.forEach(playlist => {
  1500. $("#mainList").append(`<div class="mainList item" listname="${playlist.name}" tag="playlist" onClick="openPlaylist(this);">
  1501. <div class="ui header selectable" style="margin:0px !important;" >
  1502. <img class="ui small image" src="img/list.svg" style="margin-right: 0.2em;"></img>
  1503. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%;">
  1504. ${playlist.name}
  1505. <div class="sub header fileinfo" style="color: #c7c7c7;">[${playlist.count} files]</div>
  1506. </div>
  1507. </div>
  1508. <div class="mainList rightFunctionBar" tag="moreInfo" align="center" onClick="openPlaylist(this);">
  1509. <i class="chevron right icon" style="margin-top:1.2em;"></i>
  1510. </div>
  1511. </div>`);
  1512. });
  1513. hideLeftMenu();
  1514. //Update the headers
  1515. $("#interfaceTitle").text("Playlist");
  1516. $("#AMmenuIcon").attr("class","list icon large whiteFont");
  1517. $("#interfaceDetails").text("[" + data.length + " playlist]");
  1518. });
  1519. }
  1520. function loadFolderView(){
  1521. currentMode = "folder";
  1522. currentPath = "";
  1523. var tempalte = '<div class="mainList item" filepath={filepath} id={id} tag="folder" onClick="openFolder(this);">\
  1524. <div class="ui header selectable" style="margin:0px !important;" >\
  1525. <img class="ui small image" src="img/fo.svg" style="margin-right: 0.2em;"></img>\
  1526. <div class="content whiteFont" style="padding-top: 2px; line-height:1em;width : 80%; font-weight: lighter;">\
  1527. {foldername}\
  1528. <div class="sub header fileinfo" style="color: #c7c7c7;">{fileinfo}</div>\
  1529. </div>\
  1530. </div>\
  1531. <div class="mainList rightFunctionBar" tag="moreInfo" align="center" onClick="moreFolder(this);">\
  1532. <i class="chevron right icon" style="margin-top:1.2em;"></i>\
  1533. </div>\
  1534. </div>';
  1535. $("#interfaceTitle").text("Storage");
  1536. togglePagingMode(false);
  1537. $("#AMmenuIcon").attr("class","folder open icon large whiteFont");
  1538. ao_module_agirun("Music/functions/listSong.js", {
  1539. listdir: "root",
  1540. },function(data){
  1541. $("#mainList").html("");
  1542. for (var i =0; i < data.length; i++){
  1543. var folderName = data[i][0];
  1544. var folderPath = data[i][1];
  1545. var fileCount = data[i][2];
  1546. var folderCount = data[i][3];
  1547. var box = tempalte;
  1548. box = replaceAll("{filepath}",folderPath,box);
  1549. box = replaceAll("{id}",i + 1,box);
  1550. if (folderName == ".cache" || folderName == ".trash"){
  1551. //Hidden folders
  1552. continue;
  1553. }
  1554. if (folderPath.includes("/media")){
  1555. //This is from external storage devices. List its number as well.
  1556. var tmp = folderPath.split("/");
  1557. var extStoragePath = "/" + tmp[1] + "/" + tmp[2];
  1558. box = replaceAll("{foldername}",folderName + " ( " + extStoragePath + " )",box);
  1559. }else{
  1560. //This is directory inside normal folders.
  1561. box = replaceAll("{foldername}",folderName,box);
  1562. }
  1563. /*
  1564. var fileinfo = fileinfo = "[No playable files]";
  1565. console.log(folderCount, fileCount);
  1566. if (folderCount > 0 && fileCount > 0){
  1567. fileinfo = "[" + fileCount + " files, " + folderCount +" folders]"
  1568. }else if (fileCount > 0){
  1569. fileinfo = "[" + fileCount + " files]";
  1570. }else if (fileCount == -1 && folderCount == -1){
  1571. fileinfo = "";
  1572. }
  1573. */
  1574. var fileinfo = folderPath;
  1575. box = replaceAll("{fileinfo}",fileinfo,box);
  1576. rootPaths.push(folderPath);
  1577. $("#mainList").append(box);
  1578. }
  1579. $("#interfaceDetails").text("[" + data.length + " folders]");
  1580. });
  1581. hideLeftMenu();
  1582. }
  1583. function isMobile(){
  1584. if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
  1585. return true
  1586. }
  1587. return false
  1588. }
  1589. function setWindowHash(hashValue){
  1590. hashValue = JSON.stringify(hashValue);
  1591. if (!isAndroid){
  1592. return;
  1593. }
  1594. if(history.pushState) {
  1595. window.history.pushState(null, null, '#' + hashValue);
  1596. }else {
  1597. location.hash = '#' + hashValue;
  1598. }
  1599. if(ao_module_virtualDesktop && !isMobile()){
  1600. //Update the iframe src as well
  1601. var newsrc = window.frameElement.getAttribute("src");
  1602. if (newsrc.includes("#")){
  1603. newsrc = newsrc.split("#")
  1604. newsrc.pop();
  1605. newsrc = newsrc.join("#");
  1606. }
  1607. newsrc = newsrc + "#" + hashValue;
  1608. $(window.frameElement).attr("src",newsrc);
  1609. //console.log(window.frameElement.getAttribute("src"));
  1610. }
  1611. }
  1612. function updateStateReferingURL(){
  1613. var paused = audioElement[0].paused; //Check the current playing state of the player
  1614. setWindowHash({path: currentPath, pfp:playingFileDetail,pause:paused});
  1615. }
  1616. function openFolder(object, playParameters=null){
  1617. var playIDAfterOpen = -1;
  1618. var startPaused = false;
  1619. if (playParameters !== null){
  1620. playIDAfterOpen = playParameters.playIDAfterOpen;
  1621. startPaused = playParameters.startPaused;
  1622. }
  1623. var backbtnTemplate = '<div class="mainList item extrapadding" filepath={filepath} id={id} onClick="openFolder(this);">\
  1624. <div class="ui header selectable" style="margin:0px !important;">\
  1625. <i class="angle left icon whiteFont" style="overflow:hidden;"></i>\
  1626. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%; font-weight: lighter;">\
  1627. ../\
  1628. </div>\
  1629. </div>\
  1630. </div>';
  1631. var folderTemplate = '<div class="mainList item" filepath={filepath} tag="folder" id={id} onClick="openFolder(this);">\
  1632. <div class="ui header selectable" style="margin:0px !important;">\
  1633. <img class="ui small image" src="img/fo.svg" style="margin-right: 0.2em;"></img>\
  1634. <div class="content whiteFont" style="padding-top:2px;line-height:1em; width:80%; font-weight: lighter;">\
  1635. {foldername}\
  1636. <div class="sub header fileinfo" style="color: #c7c7c7;">{fileinfo}</div>\
  1637. </div>\
  1638. </div>\
  1639. <div class="mainList rightFunctionBar" type="folder" align="center">\
  1640. <i class="chevron right icon" style="margin-top:1.2em;"></i>\
  1641. </div>\
  1642. </div>';
  1643. var fileTemplate = `<div class="mainList file item" filepath={filepath} id={id} rawname={rawname}>\
  1644. <div class="ui header selectable" style="margin:0px !important;" onClick="playSong(this);">\
  1645. <img class="ui small image" src="img/eq.svg" style="margin-right: 0.2em;"></img>
  1646. <!-- <i class="music icon whiteFont" style="overflow:hidden;"></i> -->\
  1647. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%; font-weight: lighter;">\
  1648. {songtitle}\
  1649. <div class="sub header fileinfo" style="color: #c7c7c7;">{ext} / {size}</div>\
  1650. </div>\
  1651. </div>\
  1652. <div class="topRightCorner" align="center">\
  1653. {id}\
  1654. </div>\
  1655. <div class="mainList rightFunctionBar" type="file" align="center">\
  1656. <i class="ellipsis vertical icon" style="margin-top:1.2em;"></i>\
  1657. </div>\
  1658. </div>`;
  1659. var targetPath = decodeURIComponent($(object).attr("filepath"));
  1660. if (targetPath == "root" || targetPath == "/"){
  1661. //User request to go back to storage root
  1662. loadFolderView();
  1663. return;
  1664. }
  1665. currentPath = targetPath.split("/./").join("/");
  1666. currentPath = currentPath.split("//").join("/");
  1667. $("#interfaceTitle").text(ao_module_codec.decodeHexFoldername(targetPath.substring(0,targetPath.length -1).split("/").pop()));
  1668. var parentDir = currentPath.split("/");
  1669. parentDir.pop();parentDir.pop();
  1670. parentDir = (parentDir.join("/") + "/");
  1671. //console.log(currentPath);
  1672. var backbtn;
  1673. if (rootPaths.includes(currentPath) == false){
  1674. //We are currently not at root
  1675. backbtn = backbtnTemplate;
  1676. backbtn = replaceAll("{filepath}",encodeURIComponent(parentDir),backbtn);
  1677. backbtn = replaceAll("{id}",0,backbtn);
  1678. }else{
  1679. //Create a back button to go back to root of storage
  1680. backbtn = backbtnTemplate;
  1681. backbtn = replaceAll("{filepath}","root",backbtn);
  1682. backbtn = replaceAll("{id}",0,backbtn);
  1683. }
  1684. //Request the server for a list of folders and file in this directory
  1685. ao_module_agirun("Music/functions/listSong.js", {
  1686. listdir: targetPath.split("//").join("/"),
  1687. },function(data){
  1688. $("#mainList").html("");
  1689. $("#mainList").append(backbtn);
  1690. if (Array.isArray(data)){
  1691. var folders = data[0];
  1692. var files = data[1];
  1693. //List all folders
  1694. for (var i =0; i < folders.length; i++){
  1695. var folderName = folders[i][0];
  1696. var folderPath = folders[i][1];
  1697. var fileCount = folders[i][2];
  1698. var folderCount = folders[i][3];
  1699. var box = folderTemplate;
  1700. if (folderName == ".cache" || folderName == ".trash"){
  1701. //Hidden folders
  1702. continue;
  1703. }
  1704. box = replaceAll("{filepath}",encodeURIComponent(folderPath),box);
  1705. box = replaceAll("{id}","folder-" + i + 1,box);
  1706. box = replaceAll("{foldername}",ao_module_codec.decodeHexFoldername(folderName),box);
  1707. var fileinfo = "[" + fileCount + " files]"
  1708. if (folderCount > 0){
  1709. fileinfo = "[" + fileCount + " files, " + folderCount +" folders]"
  1710. }else if (folderCount == -1){
  1711. fileinfo = folderPath;
  1712. }
  1713. box = replaceAll("{fileinfo}",fileinfo,box);
  1714. $("#mainList").append(box);
  1715. }
  1716. //List all files
  1717. for ( var i =0; i < files.length; i++){
  1718. var songInfo = files[i];
  1719. var path = songInfo[0];
  1720. var displayname = ao_module_codec.decodeUmFilename(songInfo[1]);
  1721. var ext = songInfo[2];
  1722. var size = songInfo[3];
  1723. var box = fileTemplate;
  1724. box = replaceAll("{filepath}",ao_module_utils.objectToAttr(path),box);
  1725. box = replaceAll("{id}",i + 1,box); //User count from 1
  1726. box = replaceAll("{rawname}",ao_module_utils.objectToAttr(songInfo[1]),box);
  1727. box = replaceAll("{songtitle}",displayname,box);
  1728. box = replaceAll("{ext}",ext,box);
  1729. box = replaceAll("{size}",size,box);
  1730. $("#mainList").append(box);
  1731. }
  1732. displayList = files;
  1733. totalMusicCount = files.length;
  1734. $("#mainList").append("<br><br><br><br><br><br><br>");
  1735. }else{
  1736. //Something went wrong
  1737. //console.log('[AirMusic] Something went wrong: ' + data);
  1738. loadFolderView();
  1739. return;
  1740. }
  1741. if (folders.length > 0 && files.length > 0){
  1742. $("#interfaceDetails").text("[" + files.length + " files, " + folders.length+ " folders]");
  1743. }else if (folders.length > 0){
  1744. $("#interfaceDetails").text("[" + folders.length + " folders]");
  1745. }else if (files.length > 0){
  1746. $("#interfaceDetails").text("[" + files.length + " files]");
  1747. }else{
  1748. $("#interfaceDetails").text("[0 files or folders]");
  1749. }
  1750. //Hook all the events for the moreinfo on folders
  1751. hookMoreFolderInfoClickEvent();
  1752. //Check if the current playing file is located inside this list.
  1753. highLightPlayingMusic();
  1754. //Check if auto playback is required. If yes, play it with the given filepath.
  1755. if (playIDAfterOpen != -1){
  1756. $(".mainList.item").each(function(){
  1757. if ($(this).attr("id") == playIDAfterOpen){
  1758. //This is the file that require to playback after the folder loaded
  1759. playSong($(this).find(".ts.header.selectable"),startPaused);
  1760. setTimeout(resizeQuickAdjust,500);
  1761. }
  1762. });
  1763. }
  1764. //Load thumbnail for song in list
  1765. loadThumbnailToMusicList();
  1766. });
  1767. }
  1768. function moreInfo(object){
  1769. if ($(object).parent().attr('tag') == "folder"){
  1770. //This is a folder. Ask if play as playlist
  1771. alert("Folder playback work in progress");
  1772. }else{
  1773. showMore(object);
  1774. }
  1775. }
  1776. function hookMoreFolderInfoClickEvent(){
  1777. $(".mainList.rightFunctionBar").on("click", function(e){
  1778. e.stopPropagation();
  1779. moreInfo(this);
  1780. });
  1781. }
  1782. function highLightPlayingMusic(){
  1783. //This function is used for highlighting the current playing music if the music piece is found inside the current list
  1784. $(".mainList.item").removeClass("playingTrack");
  1785. $(".mainList.item").each(function(){
  1786. var id = parseInt($(this).attr("id"));
  1787. try{
  1788. var filepath = ao_module_utils.attrToObject($(this).attr("filepath"));
  1789. }catch{
  1790. //Use back the previous method of filepath storage for compatibility
  1791. var filepath = $(this).attr("filepath");
  1792. }
  1793. //Id is ignored in the 9/9/2019 updates and only check if the path matches.
  1794. if (filepath == playingFileDetail[1]){
  1795. $(this).addClass("playingTrack");
  1796. }
  1797. //console.log([id,filepath], playingFileDetail);
  1798. });
  1799. //Update dropdownList as well if exists
  1800. $(".dropdownList.item").removeClass("playingTrack");
  1801. $(".dropdownList.item").each(function(){
  1802. try{
  1803. var filepath = ao_module_utils.attrToObject($(this).attr("filepath"));
  1804. }catch{
  1805. //Use back the previous method of filepath storage for compatibility
  1806. var filepath = $(this).attr("filepath");
  1807. }
  1808. //var filepath = $(this).attr("filepath");
  1809. if (filepath == playingFileDetail[1]){
  1810. $(this).addClass("playingTrack");
  1811. }
  1812. });
  1813. }
  1814. function hideShowMoreMenu(){
  1815. $(".showMoreMenus").fadeOut('fast');
  1816. $("#showmoreUIcover").fadeOut('fast');
  1817. //Return the playlistAddPendingFile object back to the playing one
  1818. if (playingFileDetail !== undefined){
  1819. playlistAddPendingFile = playingFileDetail[1];
  1820. }else{
  1821. //No song is being play back
  1822. playlistAddPendingFile = "";
  1823. }
  1824. }
  1825. function playFromShowMoreMenu(){
  1826. nextSong(showMoreOprPlayID - 1);
  1827. $(".showMoreMenus").fadeOut('fast');
  1828. }
  1829. function showFileInfo(){
  1830. $("#showFileInfo").show();
  1831. $("#showMoreUI").hide();
  1832. }
  1833. function startRelatedSearch(){
  1834. enterSearchMode();
  1835. $("#searchInputBar").val(showMoreoprDisplayName);
  1836. $("#searchInputBar").focus();
  1837. hideShowMoreMenu();
  1838. }
  1839. function searchYoutubeViaShowMore(){
  1840. if (showMoreoprDisplayName != "" || showMoreoprDisplayName != undefined){
  1841. var filename = showMoreoprDisplayName;
  1842. searchOnYoutube(filename);
  1843. }
  1844. }
  1845. var showMoreOprPlayID,showMoreOprFilepath, showMoreoprDisplayName;
  1846. function showMore(object){
  1847. var filepath = $(object).parent().attr("filepath");
  1848. filepath = JSON.parse(decodeURIComponent(filepath));
  1849. //User want more action on this file. assume this is the file to add
  1850. playlistAddPendingFile = filepath;
  1851. var id = $(object).parent().attr('id');
  1852. var rawname = $(object).parent().attr("rawname");
  1853. var displayName = JSON.parse(decodeURIComponent(ao_module_codec.decodeUmFilename(rawname)));
  1854. //Update global variable for quick operations
  1855. showMoreOprPlayID = id;
  1856. showMoreOprFilepath = filepath;
  1857. showMoreoprDisplayName = displayName;
  1858. $("#showMoreUI").find(".songTitle").text(displayName);
  1859. $("#showMoreUI").find(".songID").text(id);
  1860. $("#showFileInfo").find(".songTitle").text(displayName);
  1861. $("#showMoreUI").fadeIn('fast');
  1862. $("#showmoreUIcover").fadeIn('fast');
  1863. //Update fileinformation as well
  1864. if (filepath.substring(0, 12) == "/media?file="){
  1865. filepath = filepath.substring(12);
  1866. }
  1867. //Pre-render the file info
  1868. ao_module_agirun("Music/functions/getFileInfo.js", {
  1869. filepath: filepath,
  1870. }, function(data){
  1871. $("#showFileInfo").find(".filename").text(ao_module_codec.decodeUmFilename(data[0]));
  1872. $("#showFileInfo").find(".rawname").text(data[0]);
  1873. $("#showFileInfo").find(".filepath").text(data[1]);
  1874. $("#showFileInfo").find(".filesize").text(data[2] + " (" + data[3] + " Bytes)");
  1875. $("#showFileInfo").find(".filedate").text(data[4]);
  1876. });
  1877. if (currentMode != "playlist"){
  1878. $(".playlistonly").hide();
  1879. }else{
  1880. $(".playlistonly").show();
  1881. }
  1882. }
  1883. function playSongFromDropdownList(object){
  1884. //Play song from dropdown list. Hence, no need to update dropdownList
  1885. if ($(object).parent().hasClass("playingTrack")){
  1886. //This song already playing. Ignore play request.
  1887. return;
  1888. }
  1889. playSong(object);
  1890. //Check if the song is also in main list. If yes, highlight it as well
  1891. /*
  1892. $(".mainList.item").each(function(){
  1893. if ($(this).attr("filepath") == $(object).parent().attr("filepath")){
  1894. $(".mainList.item.playingTrack").removeClass("playingTrack");
  1895. $(this).addClass("playingTrack");
  1896. }
  1897. });
  1898. */
  1899. $("#dropdownSonglist").delay(500).slideUp();
  1900. highLightPlayingMusic();
  1901. }
  1902. //Move the playing song list into the dropdown song list. This list might not be the same as the one in the main list.
  1903. function parsePlayingSongList(){
  1904. $("#currentPlayingMainList").html("");
  1905. var counter = playingList.length;
  1906. var totalSize = 0.0;
  1907. var renderRange = [0, playingList.length];
  1908. if (pagingEnabled){
  1909. //Paging Enabled. Only show 1/2 max + current page song + 1/2 max
  1910. var startEndRange = getPageStartAndEndByPageNumber(currentPage);
  1911. startEndRange = [startEndRange[0] - pagingCutoffCount /2, startEndRange[1] + pagingCutoffCount / 2]
  1912. if (startEndRange[0] < 0){
  1913. startEndRange[0] = 0;
  1914. }
  1915. if (startEndRange[1] > playingList.length){
  1916. startEndRange[1] = playingList.length;
  1917. }
  1918. renderRange = startEndRange;
  1919. }
  1920. for (var i = renderRange[0]; i < renderRange[1]; i++){
  1921. var displayname = ao_module_codec.decodeUmFilename(playingList[i][1]);
  1922. if (playingList[i][3].includes("MB")){
  1923. totalSize += parseFloat(playingList[i][3].split(" ")[0]);
  1924. }else if (playingList[i][3].includes("KB")){
  1925. totalSize += parseFloat(playingList[i][3].split(" ")[0]) / 1000;
  1926. }else if (playingList[i][3].includes("GB")){
  1927. totalSize += parseFloat(playingList[i][3].split(" ")[0]) * 1000;
  1928. }
  1929. //Get thumbnail from the current list to prevent re-loading form remote
  1930. let targetThumbnail = $("#" + (i + 1)).find("img").attr("src");
  1931. let opacityShowing = "";
  1932. let realVpath = playingList[i][0].split("=");
  1933. realVpath.shift();
  1934. realVpath = realVpath.join("=");
  1935. if ($("#" + (i + 1)).length == 0 && displayList.length == playingList.length){
  1936. //Item not exists
  1937. targetThumbnail = "img/eq.svg";
  1938. opacityShowing = "opacity: 0.6;"
  1939. }else{
  1940. targetThumbnail = `../system/file_system/loadThumbnail?bytes=true&vpath=${encodeURIComponent(realVpath)}`;
  1941. }
  1942. $("#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])}">
  1943. <div class="ui header selectable" style="margin:0px !important;" onClick="playSongFromDropdownList(this);">
  1944. <img class="ui small image" src="${targetThumbnail}" onError="replaceImageToDefault(this);" style="margin-right: 0.2em;"></img>
  1945. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%;">
  1946. <span style="font-weight: lighter;">${displayname}</span>
  1947. <div class="sub header fileinfo" style="color: #c7c7c7;">${playingList[i][2]} / ${playingList[i][3]}</div>
  1948. </div>
  1949. </div>
  1950. <div class="topRightCorner" align="center">
  1951. ${i + 1}
  1952. </div>
  1953. </div>`);
  1954. $("#dropdownListSongCount").text(counter);
  1955. $("#dropdownListIDCount").text(parseInt(totalSize) + "");
  1956. }
  1957. $(".dropdownList.item").each(function(){
  1958. if ($(this).attr('filepath') == playingFileDetail[1]){
  1959. $(this).addClass("playingTrack");
  1960. }
  1961. });
  1962. }
  1963. function replaceImageToDefault(target){
  1964. $(target).attr('src', "img/eq.svg");
  1965. }
  1966. function loadSongList(type = "all"){
  1967. currentPath = "";
  1968. currentMode = "music";
  1969. $("#interfaceTitle").text("Music");
  1970. $("#AMmenuIcon").attr("class","music icon large whiteFont")
  1971. ao_module_agirun("Music/functions/listSong.js", {
  1972. listSong: type,
  1973. },function(data){
  1974. //Initialize the song list
  1975. displayList = data;
  1976. if (type == "all"){
  1977. //Caching is used in here
  1978. displayList = data.list;
  1979. if (data.cached == true){
  1980. //This is a cached version of the music list.
  1981. console.log("Updating cached song list");
  1982. ao_module_agirun("Music/functions/buildCache.js", {}, function(data){
  1983. console.log("Cache updated: ", data);
  1984. });
  1985. }
  1986. }
  1987. //Updates 2022-07-12: Check if the list is too long. If yes, use paging
  1988. let renderRange = [0,displayList.length];
  1989. if (displayList.length > pagingCutoffCount){
  1990. togglePagingMode(true);
  1991. renderRange = [0, pagingCutoffCount];
  1992. }else{
  1993. togglePagingMode(false);
  1994. }
  1995. if (playingList == []){
  1996. playingList = Array.from(displayList);
  1997. }
  1998. renderDisplayList(displayList,renderRange[0], renderRange[1] );
  1999. }, function(){
  2000. alert("Failed to access listSong API with type: " + type)
  2001. });
  2002. hideLeftMenu();
  2003. }
  2004. function renderDisplayList(displayList, start, end, callback=undefined){
  2005. $("#mainList").html("");
  2006. for ( var i =start; i < end; i++){
  2007. var songInfo = displayList[i];
  2008. var path = songInfo[0];
  2009. var displayname = ao_module_codec.decodeUmFilename(songInfo[1]);
  2010. var ext = songInfo[2];
  2011. var size = songInfo[3];
  2012. $("#mainList").append(`<div class="mainList file item" filepath="${ao_module_utils.objectToAttr(path)}" id="${i + 1}" rawname="${ao_module_utils.objectToAttr(songInfo[1])}">
  2013. <div class="ui header selectable" style="margin:0px !important;" onClick="playSong(this);">
  2014. <img class="ui small image" src="img/eq.svg" style="margin-right: 0.2em;"></img>
  2015. <div class="content whiteFont" style="padding-top:5px;line-height:1em;width : 80%; font-weight: lighter;">
  2016. ${displayname}
  2017. <div class="sub header fileinfo" style="color: #c7c7c7;">${ext} / ${size}</div>
  2018. </div>
  2019. </div>
  2020. <div class="topRightCorner" align="center">
  2021. ${i + 1}
  2022. </div>
  2023. <div class="mainList rightFunctionBar" align="center" onClick="showMore(this);">
  2024. <i class="ellipsis vertical icon" style="margin-top:1.2em;"></i>\
  2025. </div>
  2026. </div>`);
  2027. }
  2028. if (pagingEnabled){
  2029. //Append the page switch buttons
  2030. let numberOfPages = Math.ceil(parseFloat(displayList.length) / parseFloat(pagingCutoffCount));
  2031. let pageSelector = ``;
  2032. for (var i = 0; i < numberOfPages; i++){
  2033. let disabled = "";
  2034. if (i == currentPage){
  2035. disabled = "disabled";
  2036. }
  2037. 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;">
  2038. ${i + 1}
  2039. </button>`;
  2040. }
  2041. $("#mainList").append(`<div class="mainList item" style="cursor: unset;">
  2042. <div>${pageSelector}</div>
  2043. </div>`);
  2044. }
  2045. totalMusicCount = displayList.length;
  2046. $("#mainList").append("<br><br><br><br><br><br><br>");
  2047. $("#interfaceDetails").text("[" + totalMusicCount + " songs]");
  2048. highLightPlayingMusic();
  2049. //Load thumbnail for song in list
  2050. loadThumbnailToMusicList();
  2051. if (callback != undefined){
  2052. callback();
  2053. }
  2054. }
  2055. function switchToPage(pageNumber, callback=undefined){
  2056. if (!pagingEnabled){
  2057. return;
  2058. }
  2059. let thisCallback = callback;
  2060. if (pageNumber == currentPage){
  2061. //Already in that page
  2062. if (thisCallback != undefined){
  2063. callback();
  2064. }
  2065. return;
  2066. }
  2067. currentPage = pageNumber;
  2068. let startPage = pageNumber * pagingCutoffCount;
  2069. let endPage = startPage + pagingCutoffCount;
  2070. if (endPage > displayList.length){
  2071. endPage = displayList.length;
  2072. }
  2073. if (thisCallback == undefined){
  2074. renderDisplayList(displayList, startPage, endPage, function(){
  2075. window.scrollTo(0, document.body.scrollHeight);
  2076. });
  2077. }else{
  2078. renderDisplayList(displayList, startPage, endPage,thisCallback);
  2079. }
  2080. }
  2081. function getPageNumberByPlaybackId(id){
  2082. let numberOfPages = Math.ceil(parseFloat(displayList.length) / parseFloat(pagingCutoffCount));
  2083. let targetPageNo = Math.ceil(id / pagingCutoffCount) - 1;
  2084. return targetPageNo;
  2085. }
  2086. function getPageStartAndEndByPageNumber(pageNumber){
  2087. let startPage = pageNumber * pagingCutoffCount;
  2088. let endPage = startPage + pagingCutoffCount;
  2089. if (endPage > displayList.length){
  2090. endPage = displayList.length;
  2091. }
  2092. return [startPage, endPage];
  2093. }
  2094. function toggleLeftMenu(){
  2095. if (leftMenuShown){
  2096. $("#leftSideBar").animate({left: $("#leftSideBar").width() * -1}, 300,function(){
  2097. $("#leftSideBar").hide();
  2098. });
  2099. $("#sideBarCover").fadeOut();
  2100. leftMenuShown = false;
  2101. }else{
  2102. $("#leftSideBar").show();
  2103. $("#leftSideBar").animate({left:0}, 300);
  2104. $("#sideBarCover").fadeIn();
  2105. leftMenuShown = true;
  2106. }
  2107. }
  2108. function hideLeftMenu(){
  2109. if (leftMenuShown){
  2110. $("#leftSideBar").animate({left: $("#leftSideBar").width() * -1}, 300,function(){
  2111. $("#leftSideBar").hide();
  2112. });
  2113. $("#sideBarCover").fadeOut();
  2114. leftMenuShown = false;
  2115. }
  2116. }
  2117. function showFileInformation(){
  2118. ao_module_agirun("Music/functions/getFileInfo.js", {
  2119. filepath: playingFileDetail[1],
  2120. },function(data){
  2121. //console.log(data);
  2122. $("#settingInterface").hide();
  2123. $("#filepropInterface").show();
  2124. $("#filepropInterface").find(".filename").text(ao_module_codec.decodeUmFilename(data[0]));
  2125. $("#filepropInterface").find(".rawname").text(data[0]);
  2126. $("#filepropInterface").find(".filepath").text(data[1]);
  2127. $("#filepropInterface").find(".filesize").text(data[2] + " (" + data[3] + " Bytes)");
  2128. $("#filepropInterface").find(".filedate").text(data[4]);
  2129. });
  2130. }
  2131. function resizeQuickAdjust(){
  2132. //Resize the position of the leftMenu
  2133. if (!leftMenuShown){
  2134. $("#leftSideBar").css("left", $("#leftSideBar").width() * -1);
  2135. }
  2136. if ($("#playerInterface").offset().left != 0){
  2137. $("#playerInterface").css("left",window.innerWidth);
  2138. }
  2139. $("#albumnArtImage").css("max-height",window.innerHeight - 255);
  2140. setTimeout(function(){
  2141. $("#albumnArt").css({
  2142. "height": window.innerHeight - 255,
  2143. "top": (window.innerHeight / 2 - $("#albumnArtImage").height()/2)
  2144. });
  2145. },50);
  2146. //var imageTop = (window.innerHeight - 255 - $("#albumnArtImage").height()) / 2;
  2147. //$("#albumnArtImage").css("top",imageTop + "px");
  2148. }
  2149. function setStorage(configName,configValue){
  2150. ao_module_storage.setStorage("AirMusic",configName,configValue);
  2151. /*
  2152. $.ajax({
  2153. type: 'GET',
  2154. url: "../system/file_system/preference",
  2155. data: {key: "AirMusic/" + configName,value:configValue},
  2156. success: function(data){},
  2157. async:true
  2158. });
  2159. */
  2160. return true;
  2161. }
  2162. function loadStorage(configName){
  2163. /*
  2164. var result = "";
  2165. $.ajax({
  2166. type: 'GET',
  2167. url: "../system/file_system/preference",
  2168. data: {key: "AirMusic/" + configName},
  2169. success: function(data){
  2170. if (data.error !== undefined){
  2171. result = "";
  2172. }else{
  2173. result = data;
  2174. }
  2175. },
  2176. error: function(data){result = "";},
  2177. async:false,
  2178. timeout: 3000
  2179. });
  2180. return result;
  2181. */
  2182. return ao_module_storage.loadStorage("AirMusic",configName);
  2183. }
  2184. //Wipe controller for mobile users
  2185. $("#albumnArt")[0].addEventListener('touchstart', handleTouchStart, false);
  2186. $("#albumnArt")[0].addEventListener('touchmove', handleTouchMove, false);
  2187. var xDown = null;
  2188. var yDown = null;
  2189. function getTouches(evt) {
  2190. return evt.touches || // browser API
  2191. evt.originalEvent.touches; // jQuery
  2192. }
  2193. function handleTouchStart(evt) {
  2194. const firstTouch = getTouches(evt)[0];
  2195. xDown = firstTouch.clientX;
  2196. yDown = firstTouch.clientY;
  2197. };
  2198. function handleTouchMove(evt) {
  2199. if ( ! xDown || ! yDown ) {
  2200. return;
  2201. }
  2202. var xUp = evt.touches[0].clientX;
  2203. var yUp = evt.touches[0].clientY;
  2204. var xDiff = xDown - xUp;
  2205. var yDiff = yDown - yUp;
  2206. if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) {/*most significant*/
  2207. if ( xDiff > 0 ) {
  2208. /* left swipe */
  2209. //Going to the next song
  2210. nextSong();
  2211. } else {
  2212. /* right swipe */
  2213. //Going back one song
  2214. previousSong();
  2215. }
  2216. } else {
  2217. if ( yDiff > 0 ) {
  2218. /* up swipe */
  2219. } else {
  2220. /* down swipe */
  2221. }
  2222. }
  2223. /* reset values */
  2224. xDown = null;
  2225. yDown = null;
  2226. };
  2227. //Handle audio progress to time conversion
  2228. function secondsToHms(d) {
  2229. d = Number(d);
  2230. var h = Math.floor(d / 3600);
  2231. var m = Math.floor(d % 3600 / 60);
  2232. var s = Math.floor(d % 3600 % 60);
  2233. if (h > 0 && h < 10){
  2234. dh = "0" + h + ":";
  2235. }else if (h == 0){
  2236. dh = "";
  2237. }else{
  2238. dh = h + ":";
  2239. }
  2240. if (m > 0 && m < 10){
  2241. dm = "0" + m + ":";
  2242. }else if (m == 0){
  2243. if (h > 0){
  2244. dm = "00:";
  2245. }else{
  2246. dm = "0:";
  2247. }
  2248. }else{
  2249. dm = m + ":";
  2250. }
  2251. if (s > 0 && s < 10){
  2252. ds = "0" + s;
  2253. }else if (s == 0){
  2254. if (m > 0 || h > 0){
  2255. ds = "00";
  2256. }else{
  2257. ds = "00";
  2258. }
  2259. }else{
  2260. ds = s;
  2261. }
  2262. return dh + dm + ds;
  2263. }
  2264. //Handle window resize events
  2265. $(window).on("resize", function(){
  2266. resizeQuickAdjust();
  2267. });
  2268. function AllQuickMenuHidden(){
  2269. var result = true;
  2270. $(".quickMenu").each(function(){
  2271. if ( $(this).is(':visible') ){
  2272. result = false;
  2273. }
  2274. });
  2275. return result;
  2276. }
  2277. function AllSubMenuHidden(){
  2278. var result = true;
  2279. $(".showMoreMenus").each(function(){
  2280. if ( $(this).is(':visible') ){
  2281. result = false;
  2282. }
  2283. });
  2284. return result;
  2285. }
  2286. //Handle back button press on mobile devices
  2287. function handleBackButton() {
  2288. if (!AllQuickMenuHidden()){
  2289. hideAllquickMenu();
  2290. window.history.pushState({}, '');
  2291. }else if (mainPlayerShown()){
  2292. //Close the main Menu
  2293. hideMainPlayerInterface();
  2294. window.history.pushState({}, '');
  2295. }else if (!AllSubMenuHidden()){
  2296. $(".showMoreMenus").fadeOut('fast');
  2297. $("#showmoreUIcover").fadeOut('fast');
  2298. window.history.pushState({}, '');
  2299. }else{
  2300. window.history.back();
  2301. }
  2302. }
  2303. window.addEventListener('popstate', handleBackButton);
  2304. window.history.pushState({}, '');
  2305. </script>
  2306. </body>
  2307. </html>