index.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. //ArOZ Online BETA control system
  2. //Declare Global Variables
  3. var ShareMode = $("#DATA_OBJECT_shareMode").text().trim() == "true";
  4. if ($("#DATA_OBJECT_ShareSong").text().trim() !== ""){
  5. var ShareSong = JSON.parse($("#DATA_OBJECT_ShareSong").text());
  6. }
  7. if ($("#DATA_OBJECT_songlist").text().trim() !== ""){
  8. var songlist = JSON.parse($("#DATA_OBJECT_songlist").text().trim());
  9. }
  10. var search_keyword = $("#DATA_OBJECT_search_keyword").text().trim();
  11. if ($("#DATA_OBJECT_embedded").text().trim() == "true"){
  12. var embedded = true;
  13. }else{
  14. var embedded = false;
  15. }
  16. var pwa = $("#DATA_OBJECT_pwaMode").text().trim() == "true";
  17. var extStorageMode = $("#DATA_OBJECT_extStorageMode").text().trim() == "true";
  18. var extStorageFolder = $("#DATA_OBJECT_extStorageFolder").text().trim();
  19. var downloadmode = false;
  20. var lastactiveid = -1;
  21. var RepeatMode = 2;
  22. var SearchBarOn = false;
  23. var playingSong = [];
  24. var inVDI = !(!parent.isFunctionBar);
  25. var extDiskAccessAPI="../SystemAOB/functions/extDiskAccess.php?file=";
  26. ////////////////////////////
  27. $( document ).ready(function() {
  28. //Set the default path selector value
  29. if (extStorageMode){
  30. $("#basedirPath").val("/media/" + extStorageFolder);
  31. }
  32. if (pwa){
  33. $(".pwa").each(function(){
  34. $(this).addClass('disabled');
  35. });
  36. $(".pwahide").each(function(){
  37. $(this).hide();
  38. });
  39. }
  40. var is_safari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  41. if (is_safari){
  42. //This is added to fix some glitch on Safari tested on a Mac Machine
  43. $("body").css("background-color:white;")
  44. }
  45. if (embedded && inVDI){
  46. //Update functions called following the AOB 11-8-2018 updates
  47. //Now, the embedded windows can ask for resize properties and icon from the system
  48. //If it is currently in VDI, force the current window size and resize properties
  49. var windowID = $(window.frameElement).parent().attr("id");
  50. parent.setWindowFixedSize(windowID + "");
  51. parent.setWindowPreferdSize(windowID + "",640,173);
  52. parent.cacheWindowSize($(window.frameElement).parent().find("iframe").attr("src"),640,173,false);
  53. parent.setWindowIcon(windowID + "","music");
  54. }
  55. if (inVDI){
  56. //It is currently in Virtual Desktop Mode, make it semi-transparent!
  57. //$('body').css('background','rgba(255,255,255,0.7)');
  58. setInterval(function() {
  59. GvolDisplay();
  60. },1000);
  61. if ($("#backBtn").length > 0){
  62. $("#backBtn").attr("href","");
  63. }
  64. var windowID = $(window.frameElement).parent().attr("id");
  65. parent.setGlassEffectMode(windowID + "");
  66. parent.setWindowIcon(windowID + "","music")
  67. }else{
  68. $("#fuctmenu").css("bottom","0px");
  69. }
  70. if (search_keyword != ""){
  71. //In Search Mode
  72. $( "#sbinput" ).val(search_keyword);
  73. SearchBarOn = true;
  74. }else{
  75. //Not in Search Mode
  76. $("#searchbar").hide();
  77. }
  78. $('#downloadmode_reminder').hide();
  79. $('#playbtn').attr('class', 'play icon');
  80. //Load the global volume from the stored data
  81. var globalvol = localStorage.getItem("global_volume");
  82. var player = document.getElementById("player");
  83. //console.log("Global Volume" + globalvol.toString());
  84. if (!globalvol){
  85. globalvol = 0.6;
  86. }
  87. player.volume = parseFloat(globalvol);
  88. $('#voldis').html(" " + (Math.round(player.volume * 100)).toString() + "%");
  89. //Load the repeat mode from stored data
  90. var repmode = localStorage.getItem("repeat_mode");
  91. if (repmode == 0){
  92. //0
  93. $('#repmode').html(' Single');
  94. RepeatMode = 0;
  95. }else if (repmode == 1){
  96. //1
  97. $('#repmode').html(' ALL');
  98. RepeatMode = 1;
  99. }else{
  100. //2
  101. $('#repmode').html(' None');
  102. RepeatMode = 2;
  103. }
  104. //console.log(songlist);
  105. if (embedded == true && repmode == 1){
  106. //Now allow all mode in embedded
  107. $('#repmode').html(' None');
  108. RepeatMode = 2;
  109. }
  110. if (ShareMode){
  111. PlaySong(ShareSong[0],ShareSong[1],ShareSong[2]);
  112. window.setTimeout(CheckPlaying, 500);
  113. }
  114. });
  115. //On Pause or Play using Android notification on Firefox / Chrome
  116. var aud = document.getElementById("player");
  117. aud.onpause = function() {
  118. //Paused by the user on notification
  119. $('#playbtn').attr('class', 'play icon');
  120. };
  121. aud.onplay = function() {
  122. //Play by the user on notification
  123. $('#playbtn').attr('class', 'pause icon');
  124. };
  125. function GvolDisplay(){
  126. var globalvol = (Math.round(GetStorage('global_volume') * 100)) / 100;
  127. var audio = document.getElementById("player");
  128. audio.volume = globalvol;
  129. $('#voldis').html(" " + (Math.round(audio.volume * 100)).toString() + "%");
  130. }
  131. //These function is for ArOZ Online System quick storage data processing
  132. function CheckStorage(id){
  133. if (typeof(Storage) !== "undefined") {
  134. return true;
  135. } else {
  136. return false;
  137. }
  138. }
  139. function GetStorage(id){
  140. //All data get are string
  141. return localStorage.getItem(id);
  142. }
  143. function SaveStorage(id,value){
  144. localStorage.setItem(id, value);
  145. return true;
  146. }
  147. function toggleSearch(){
  148. //Id of Search Bar: searchbar
  149. if (SearchBarOn){
  150. //Need to close the Search Bar
  151. $("#searchbar").css("display", "none");
  152. SearchBarOn = false;
  153. }else{
  154. $("#searchbar").css("display", "block");
  155. SearchBarOn = true;
  156. $(window).scrollTop(0);
  157. $("#sbinput").focus();
  158. }
  159. }
  160. $('#searchbar').bind("enterKey",function(e){
  161. var keyword = $( "#sbinput" ).val();
  162. if (keyword != ""){
  163. window.location.href = "../Audio/index.php?search=" + keyword;
  164. }else{
  165. window.location.href = "../Audio/";
  166. }
  167. });
  168. $('#searchbar').keyup(function(e){
  169. if(e.keyCode == 13)
  170. {
  171. $(this).trigger("enterKey");
  172. }
  173. });
  174. function toggledownload(){
  175. if (downloadmode == true){
  176. $('#downloadmode_reminder').stop();
  177. $('#sbtext').html('Download Mode Disabled.');
  178. $("#downloadmodeBtn").css("background-color","");
  179. $('#downloadmode_reminder').fadeIn('slow').delay(2000).fadeOut('slow');
  180. downloadmode = false;
  181. }else{
  182. $('#downloadmode_reminder').stop();
  183. $('#sbtext').html('Download Mode Enabled.');
  184. $("#downloadmodeBtn").css("background-color","#b0ffaa");
  185. $('#downloadmode_reminder').fadeIn('slow').delay(2000).fadeOut('slow');
  186. downloadmode = true;
  187. }
  188. }
  189. function getRealID(textid){
  190. return parseInt(textid.replace("AudioID",""));
  191. }
  192. function change(sourceUrl) {
  193. var audio = $("#player");
  194. if (extStorageMode == false){
  195. $("#player").attr("src", sourceUrl);
  196. }else{
  197. $("#player").attr("src", extDiskAccessAPI + sourceUrl);
  198. }
  199. audio[0].pause();
  200. audio[0].load();//suspends and restores all audio element
  201. //audio[0].play(); changed based on Sprachprofi's comment below
  202. audio[0].oncanplaythrough = audio[0].play();
  203. }
  204. function share(){
  205. var shareSong = playingSong[0];
  206. var displayName = playingSong[1];
  207. var audioID = playingSong[2];
  208. if (shareSong != '' && shareSong != null){
  209. if (inVDI){
  210. window.parent.newEmbededWindow("QuickSend/index.php?share=" + "http://" + window.location.host + window.location.pathname + "?share=" + shareSong + "<and>display=" + displayName + "<and>id=" + audioID,'QuickSend','share alternate','QuickSend',475,700);
  211. }else{
  212. window.location.href="../QuickSend/index.php?share=" + "http://" + window.location.host + window.location.pathname + "?share=" + shareSong + "<and>display=" + displayName + "<and>id=" + audioID;
  213. }
  214. }
  215. }
  216. function PlaySong(name,displayname,id){
  217. if (downloadmode == false){
  218. //This operation is for choosing song
  219. $('#songname').html('NOW PLAYING || '+ displayname);
  220. change(name);
  221. playingSong = [name,displayname,id];
  222. //console.log(playingSong);
  223. $('#playbtn').attr('class', 'pause icon');
  224. if (lastactiveid.toString() != id.toString()){
  225. $('#' + lastactiveid).attr('class', 'ts item');
  226. $('#' + id.toString()).attr('class', 'ts item active');
  227. }
  228. lastactiveid = id;
  229. $(document).prop('title', displayname);
  230. //console.log(lastactiveid);
  231. if (inVDI){
  232. //If it is currently in VDI, update the floatWindow title as well
  233. var windowID = $(window.frameElement).parent().attr("id");
  234. parent.changeWindowTitle(windowID + "",displayname);
  235. parent.setGlassEffectMode(windowID + "");
  236. }
  237. }else if (downloadmode == true){
  238. //This operation is for downloading the audio file
  239. saveAs(name,displayname);
  240. }
  241. }
  242. function CheckPlaying(){
  243. var player = document.getElementById('player');
  244. if (player.paused){
  245. //Chrome does not allow instant playing of audio so user have to click the btn themselves.
  246. $('#playbtn').attr('class', 'play icon');
  247. }
  248. }
  249. function NextSong(){
  250. lastactiveid = parseInt(lastactiveid);
  251. if (lastactiveid != "undefined"){
  252. if (lastactiveid < songlist.length - 1){
  253. PlaySong(songlist[lastactiveid + 1][0],songlist[lastactiveid + 1][1],songlist[lastactiveid + 1][2]);
  254. }else{
  255. PlaySong(songlist[0][0],songlist[0][1],songlist[0][2]);
  256. }
  257. }
  258. }
  259. function PreviousSong(){
  260. lastactiveid = parseInt(lastactiveid);
  261. if (lastactiveid != "undefined"){
  262. if (lastactiveid > 0){
  263. PlaySong(songlist[lastactiveid - 1][0],songlist[lastactiveid - 1][1],songlist[lastactiveid - 1][2]);
  264. }
  265. }
  266. }
  267. function saveAs(uri, filename) {
  268. if (extStorageMode){
  269. uri = extDiskAccessAPI + uri + "&mode=download&filename=" + JSON.stringify(filename);
  270. }
  271. var link = document.createElement('a');
  272. if (typeof link.download === 'string') {
  273. document.body.appendChild(link); // Firefox requires the link to be in the body
  274. link.download = filename;
  275. link.href = uri;
  276. link.click();
  277. document.body.removeChild(link); // remove the link when done
  278. } else {
  279. location.replace(uri);
  280. }
  281. }
  282. function Show_Audio_Attrubute(){
  283. $("#audio_attr").fadeIn("slow");
  284. }
  285. function Hide_Audio_Attrubute(){
  286. $("#audio_attr").fadeOut("slow");
  287. }
  288. function repeatmode(){
  289. //This set the repeat mode for the browser reference.
  290. var repmode = localStorage.getItem("repeat_mode");
  291. // 0 = Single Repeat, repeat the same song
  292. // 1 = All Repeat, repeat when it reached the bottom of the list
  293. // 2 = No Repeat, stop after finishing this song.
  294. if (repmode == 0){
  295. //0 -> 1
  296. if (embedded == true){
  297. repmode = 2;
  298. $('#repmode').html(' None');
  299. localStorage.setItem("repeat_mode", 2);
  300. }else{
  301. $('#repmode').html(' ALL');
  302. localStorage.setItem("repeat_mode", 1);
  303. }
  304. }else if (repmode == 1){
  305. //1 -> 2
  306. $('#repmode').html(' None');
  307. localStorage.setItem("repeat_mode", 2);
  308. }else{
  309. //2 -> 0
  310. $('#repmode').html(' Single');
  311. localStorage.setItem("repeat_mode", 0);
  312. }
  313. }
  314. function playbtn(){
  315. if (document.getElementById('player').paused == true){
  316. $('#playbtn').attr('class', 'pause icon');
  317. $('#player').trigger('play');
  318. }else{
  319. $('#playbtn').attr('class', 'play icon');
  320. $('#player').trigger('pause');
  321. }
  322. }
  323. function stopbtn(){
  324. $('#player').trigger('pause');
  325. document.getElementById('player').currentTime = 0;
  326. $('#playbtn').attr('class', 'play icon');
  327. }
  328. $("#progressbardiv").click(function(e){
  329. var parentOffset = $(this).parent().offset();
  330. //or $(this).offset(); if you really just want the current element's offset
  331. var relX = e.pageX - parentOffset.left;
  332. var relY = e.pageY - parentOffset.top;
  333. var divwidth = $(this).parent().width();
  334. var ratio = relX / divwidth;
  335. var player = document.getElementById('player');
  336. var targettime = Math.round(player.duration * ratio);
  337. player.currentTime = parseFloat(targettime);
  338. //console.log(ratio);
  339. });
  340. var player = document.getElementById('player');
  341. //For every time update
  342. player.addEventListener("timeupdate", function() {
  343. var currentTime = player.currentTime;
  344. var duration = player.duration;
  345. $('#timecode').html(" " + FTF(Math.round(currentTime)) + "/" + FTF(Math.round(duration)));
  346. $('#audioprogress').stop(true,true).animate({'width':(currentTime)/duration*100+'%'},0,'linear');
  347. });
  348. //When the audio file is loaded
  349. player.addEventListener("canplay", function() {
  350. //Load the global volume from the stored data
  351. var globalvol = localStorage.getItem("global_volume");
  352. //console.log("Global Volume" + globalvol.toString());
  353. if (!globalvol){
  354. globalvol = 0.6;
  355. }
  356. player.volume = globalvol;
  357. $('#voldis').html(" " + (Math.round(player.volume * 100)).toString() + "%");
  358. //Load the repeat mode from stored data
  359. var repmode = localStorage.getItem("repeat_mode");
  360. if (embedded == true){
  361. if (repmode == 1){
  362. $('#repmode').html(' None');
  363. repmode = 2;
  364. }
  365. }
  366. if (repmode == 0){
  367. //0
  368. $('#repmode').html(' Single');
  369. RepeatMode = 0;
  370. }else if (repmode == 1){
  371. //1
  372. $('#repmode').html(' ALL');
  373. RepeatMode = 1;
  374. }else{
  375. //2
  376. $('#repmode').html(' None');
  377. RepeatMode = 2;
  378. }
  379. });
  380. //Event when the player finished the audio playing
  381. player.addEventListener("ended", function() {
  382. var repmode = localStorage.getItem("repeat_mode");
  383. if (repmode == 0){
  384. //0
  385. $('#repmode').html(' Single');
  386. RepeatMode = 0;
  387. }else if (repmode == 1){
  388. //1
  389. $('#repmode').html(' ALL');
  390. RepeatMode = 1;
  391. }else{
  392. //2
  393. $('#repmode').html(' None');
  394. RepeatMode = 2;
  395. }
  396. if (embedded == true){
  397. if (RepeatMode == 1){
  398. RepeatMode = 2;
  399. $('#repmode').html(' None');
  400. }
  401. }
  402. if (RepeatMode == 0){
  403. stopbtn();
  404. $('#player').trigger('play');
  405. }else if (RepeatMode == 1){
  406. NextSong();
  407. }else{
  408. stopbtn();
  409. }
  410. });
  411. function volUp(){
  412. var audio = document.getElementById("player");
  413. if (audio.volume > 0.95){
  414. audio.volume = 1;
  415. }else{
  416. audio.volume += 0.05;
  417. }
  418. $('#voldis').html(" " + (Math.round(audio.volume * 100)).toString() + "%");
  419. localStorage.setItem("global_volume", audio.volume);
  420. }
  421. function volDown(){
  422. var audio = document.getElementById("player");
  423. if (audio.volume < 0.05){
  424. audio.volume = 0;
  425. }else{
  426. audio.volume -= 0.05;
  427. }
  428. $('#voldis').html(" " + (Math.round(audio.volume * 100)).toString() + "%");
  429. localStorage.setItem("global_volume", audio.volume);
  430. }
  431. $("#basedirPath").change(function(){
  432. var selectedItem = $("#basedirPath").find(":selected").text();
  433. if (selectedItem == "Internal Storage"){
  434. if (inVDI){
  435. window.location.href = "index.php?mode=fw";
  436. }else{
  437. window.location.href = "index.php";
  438. }
  439. }else{
  440. if (inVDI){
  441. window.location.href = "index.php?mode=fw&extstorage=" + selectedItem.split("/").pop();
  442. }else{
  443. window.location.href = "index.php?extstorage=" + selectedItem.split("/").pop();
  444. }
  445. }
  446. });
  447. //Scroll Controller
  448. $(window).scroll(function (event) {
  449. var scroll = $(window).scrollTop();
  450. if (scroll > 200){
  451. $('#YamiPlayer').css('position', 'fixed');
  452. $('#YamiPlayer').css('top', '0');
  453. $('#YamiPlayer').css('right', '0');
  454. $('#YamiPlayer').css('width', '100%');
  455. $('#YamiPlayer').css('z-index', '1000');
  456. }else if (scroll < 50){
  457. $('#YamiPlayer').css('position', '');
  458. $('#YamiPlayer').css('top', '');
  459. $('#YamiPlayer').css('width', '100%');
  460. $('#YamiPlayer').css('right', '');
  461. $('#YamiPlayer').css('z-index', '');
  462. }
  463. });
  464. function FTF(time)
  465. {
  466. // Hours, minutes and seconds
  467. var hrs = ~~(time / 3600);
  468. var mins = ~~((time % 3600) / 60);
  469. var secs = time % 60;
  470. // Output like "1:01" or "4:03:59" or "123:03:59"
  471. var ret = "";
  472. if (hrs > 0) {
  473. ret += "" + hrs + ":" + (mins < 10 ? "0" : "");
  474. }
  475. ret += "" + mins + ":" + (secs < 10 ? "0" : "");
  476. ret += "" + secs;
  477. return ret;
  478. }