Jump to content


  • Content Count

  • Joined

  • Last visited

Everything posted by ajoo

  1. Hi all ! Is it possible to define / set more than one path for the xsendfile module to look up ? Request an example if someone knows how to do that. Thanks all !
  2. Hi Kicken, Maxxd, all else ! Sorry for the delay in my response. It was Diwali week in India, the light of festivals to celebrate the auspicious occasion of the return of Lord Ram from from an exile ! So a very Happy Diwali to all !! I am making amends by posting fresh bit of code. @Maxxd Thanks for finding that syntax error. Surely It occurred while I was deleting comments etc from the pasted code to clean it a bit. Please find below the complete code that works. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <meta charset="UTF-8"> <h2>My Sounds</h2> <span class='btn'>Play</span> <script> $(document).ready(function(){ $('.btn').click( function(){ startSound(); }); function getSoundURL(soundURL){ $.ajax({ type: "GET", url: 'playsound1.php', data: {sf: soundURL}, dataType: 'binary', xhrFields: { responseType: 'blob' }, success: function(blob){ alert("YEY !"); window.URL = window.URL || window.webkitURL; var blob = new Blob([blob]); var link=document.createElement('a'); link.href=window.URL.createObjectURL(blob); blob = null; var audio = new Audio(link.href); audio.type = 'audio/mpeg'; console.log(audio); audio.play(); } }); } function startSound() { var playURL = "ready.mp3"; audio = getSoundURL(playURL); // This is where,i want ajax to return the audio object. // audio.type = 'audio/mpeg'; // audio.play(); } }); </script> playsound1.php (simplified) if($_SERVER["REQUEST_METHOD"]==="GET") { $sounddir = "sounddir/"; // Path to sound files $sf = html_escape($_GET["sf"]); $sf = $sounddir.$sf; $type = "audio/mpeg"; // The sound file has an extention of .mp3 header("X-Sendfile: ".$sf); header("Content-Type: " .$type); } The above code works but does not return the sound object back to the calling code as asked earlier. Would appreciate some help on that. There are quite some examples that i came across on callbacks but I am not sure which is the latest method to use since it has modified a lot over the years and a lot of those examples use deprecated code. Thanks !!
  3. Hi, In an earlier topic I was trying to get the sounds to play off the server. The sound file being served by the server. Eventually I have a situation where I have finally managed to get the sound to play within the ajax block. The lines of code shown execute and the sound is played. However if I try and pass the audio object back to the calling function (// return audio) it ends up in the calling code as undefined !??? Could this be because of the asynchronous nature of ajax ? If so, Is there a way to get around it and pass the object back to the calling function successfully? <script> $(document).ready(function(){ $('.btn').click( function() startSound(); }); function startSound() { $('.btn').disabled = true; playURL = getURL(); audio = playServerURL(playURL); console.log(audio); --------------------------------- ( ERROR--A ) // alert("Received Data"); // var audio = new Audio(playURL); // audio.type = 'audio/mpeg'; // audio.play(); // audio.onended = getNextUrl; } // Get sounds off the server $.ajax({ type: 'GET', url: 'playsound1.php', data: {sf: 'ready.mp3'}, dataType:"binary", success:function(data){ // doesn't trigger alert("Yey !"); // does not popup . . . audio = new Audio(audBlob); var audio = new Audio(audBlob); // return audio; audio.type = 'audio/mp3'; console.log(audio); -------------------------------------- (Message B) audio.play(); } }) }) </script> console.log() inside the ajax (Message -- B) gives the audio object console.log() inside the startSound gives (Error -- A) :- Please can someone shed light on this. Thanks all !
  4. Hi Kicken ! Thanks a lot for the response ! I have tried out your idea to process the response as a binary blob. I think that your idea about JS bungling the response from the server is absolutely correct. I have tried out the code in the link provided by you. I have no idea of using the xhr object so I just tried it as is and the blob it returned is also, unfortunately, not a valid audio binary. I then searched and found a JQuery equivalent of the code and it is below but here too the binary received ( on inspecting the response in the network ) is not a valid audio binary. Surprisingly, the success function does not trigger and so the alert("Yeah !"); does not occur. So does that means that the response received from the server is invalid ? If so, why does JS not give any error then ? Here's the code that I have tried :- server_sound.html <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <meta charset="UTF-8"> <h2>My Sounds</h2> <span class='btn'>Play</span> <script> $(document).ready(function(){ $('.btn').click( function(){ $.ajaxSetup({ beforeSend:function(jqXHR,settings){ if (settings.dataType === 'binary'){ settings.xhr().responseType='arraybuffer'; settings.processData=false; } } }) //use ajax now $.ajax({ type: 'GET', url: 'playsound1.php', data: {sf: 'ready.mp3'}, dataType:"binary", success:function(data){ // doesn't trigger alert("Yeah !"); // does not popup console.log(data); //ArrayBuffer console.log(new Blob([data])) // Blob } }) }) }) </script> playsound1.php if($_SERVER["REQUEST_METHOD"]==="GET") { $sounddir = "sounddir/"; // Path to sound files $sf = html_escape($_GET["sf"]); $sf = $sounddir.$sf; $type = "audio/mpeg"; // The sound file has an extention of .mp3 header("X-Sendfile: ".$sf); header("Content-Type: " .$type); } Hoping to find a solution to this. Thanks !!
  5. Hi all ! Trying out the same code in Firefox gave the following errors: while Chrome the following error. The <audio preload = " auto " src = "ID3\.... " expands to show the full binary loaded. But the message is showing " HTTP load failed with status 404" ? The object is already loaded as audio. I also cannot understand the subsequent "GET http://franchisee.com/newmovie/ID3" because the audio is already loaded.Is it trying to find a file beginning with ID3 or something ?? Why should it do that instead of returning the already loaded object ? Rather confusing to me . Hope someone can shed some light on this. Thanks all !
  6. Hi cyberRoot, Thanks for the response. I have checked this already. As you can see, in the example that you refer to, the audio file is loaded directly from a file and the eventListener works in that case. In the other case the data is returned as a part of the get response. The binary blob is received and can be seen in the console. The eventListener does not get triggered this way. Further the two blobs received in the two different ways are also slightly different. Just for the sake of checking / digging further, If I save the audio object created usinf xsendfile in a file as an mp3. It does not play and gives an error. Hoping someone can help resolve this. Thanks !.
  7. Hi all ! In am trying to modify the following snippet html <audio src = "playsound1.php?test=1.mp3" /> php (simplified) <?php . . . header('X-Sendfile: 1.mp3'); header('Content-Type: audio/mpeg'); ?> so that I don't have to use the <audio .. /> tag. I want to use the jQuery get to retrieve the sound instead. Here's what I have tried doing. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <h2>My Sounds</h2> <span class='btn'>Play</span> <script> $(document).ready(function(){ $('.btn').click( function(){ $.get( "playsound1.php", {sf: "ready.mp3"}, function( data ) { var audio = new Audio(data); audio.type = "audio/mpeg"; // console.log(audio); audio.play(); }); }); }); </script> But it ends up with an error. I think I need to use some kind of an event to check that the data is loaded before audio.play() is called but i am not sure how to do that. Looking for some advise to achieve this. Thanks all !
  8. hI all ! I just updated this thread with a question yesterday and I am not sure if this pops "in the new threads to be answered" section where ever that maybe. Earlier it was on the home page as an aside window. So i am trying this once again and noting the views thus far to see if its being read. I Kindly request the Gurus / experts to inspect the code for their views / suggestions to hammer out a solution if one is possible in this manner. Thanks loads !
  9. Hi all ! Just like to continue this old thread since the problem is related. I hope that is ok. I have my sounds going great. However, I am trying to get my sound files a bit safe by placing them above the document root and serving them off the server. The code below passes the filename of the audio to invoke the server to serve the same. <html> <head> <title>Test Sound</title> </head> <body> <a onclick="playSound()"> Play</a> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> function playSound() { alert("Play Sound"); var testsound = "beep07.wav"; var data; alert(testsound); $.post("playsound.php", {sf: testsound}, function(data,status){ alert("CP1"); alert("Data : "+data+"\nStatus : "+status); var audio = new Audio(data); audio.type = 'audio/wav'; audio.play(); alert("Thanks"); }); } </script> </body> </html> Everything works fine except that it ends up with a I believe that this is happening because it needs an event to fire the sound which is exactly how it was triggered on a button press. But because the server was involved and the file was not lifted directly (by a path and filename) I think, that this error occurred. So how can this be resolved ? Another thing is that this is just a trial code to get a sound going. However what i really would need is a a stream of sound files that I need to invoke on a button press. For e.g. i can have an array like ['a.mp3','b.mp3','c.mp3','d.mp3','e.mp3'] to sound a,b,c,d,e one after the other once the start button is clicked. Thanks all for any help on this.
  10. Hi Guru Barand ! Sir this finally achieves it. create temporary table mina1111_a Select * from ( select a.RecNo , a.User , a.V_Score , @count := @count-1 as reccount from ajoo as a JOIN (select @count:=6) as init where User = 'mina1111' ORDER BY RecNo DESC LIMIT 5)sub Order by RecNo ASC; create temporary table mina1111_b Select * from ( select a.RecNo , a.User , a.V_Score , @count := @count-1 as reccount from ajoo as a JOIN (select @count:=6) as init where User = 'mina1111' ORDER BY RecNo DESC LIMIT 5)sub Order by RecNo ASC; SELECT a.RecNo , a.V_Score , ( SELECT AVG(b.V_Score) as avscor FROM mina1111_b b WHERE reccount BETWEEN a.reccount-4 and a.reccount ) as av5 FROM mina1111_a a JOIN ajoo j using (RecNo); WHERE a.reccount > 4; finally gives +-------+------------+--------+ | RecNo | Wrt_V_Sums | av5 | +-------+------------+--------+ | 10 | 5 | 5.0000 | | 11 | 0 | 2.5000 | | 13 | 1 | 2.0000 | | 14 | 1 | 1.7500 | | 15 | 1 | 1.6000 | +-------+------------+--------+ Thank you !!🙏 P.S. I thought if there was a way of generalizing the "RecNo > N " so as to target the last 5-rows or last x-rows ( in general ) , the querys to create the temp tables would have been so much easier.
  11. Hi Guru Barand, I am able to get the results I want by modifying your query slightly as below: ( Last line "AND RecNo > 9 " is only added). create temporary table mina1111_a select a.recno , a.v_score , @count := @count+1 as reccount from ajoo a JOIN (select @count:=0) as init where user = 'mina1111 AND RecNo > 9'; same for table mini1111_b. and i get the result i want. The only problem is that i can use > 9 here because i get 5 rows with that. How can I generalize this to get the last 5 rows each time no matter how many rows there may be in the table ajoo ? Thanks loads !
  12. yes Guru Barand ! I have been trying without success. I'll try some more. Thanks !
  13. Sir I understand that but I am unable to get those averages from the table that I created. As mentioned in #3, even though I get the 5 rows, I keep getting the Can't reopen error when I try and use it for getting the averages. For your convenience here it is again. create temporary table mina1111_a Select * from ( select a.RecNo , a.User , a.V_Score from ajoo as a where User = 'mina1111' ORDER BY RecNo DESC LIMIT 5)sub Order by RecNo ASC; which gives the table +-------+--------------+------------+ | RecNo | User | V_Score | +-------+--------------+------------+ | 10 | mina1111 | 5 | | 11 | mina1111 | 0 | | 13 | mina1111 | 1 | | 14 | mina1111 | 1 | | 15 | mina1111 | 1 | +-------+--------------+------------+ However when i use this table to calculate the averages, it gives an error and I think that's because I cannot use the temp tables like this. It says cannot reopen the table. Kindly help resolve. Thanks
  14. Hi Guru Barand, Sir then how do I go about getting the average values of "your results" ? Using just the 5 rows. Thank you !
  15. Hi Guru Barand ! Sir, You are correct but so am I because I said I want the derived table to be considered as the complete and only table itself thereby ignoring all the rows / values before the last 5 rows. In which case this below is the only table. All other values are discarded and averages are calculated by taking RecNo 9 as the first record and so on. In that case "your result" values would fit. +-------+----------+---------+----------+-------------------+-----------------+ | recno | user | v_score | reccount | last5 | av5 = last5/5 | my results your results +-------+----------+---------+----------+-------------------+-----------------+ | 9 | mina1111 | 4 | 5 | 2 + 4 + 3 + 2 + 4 | 15/5 = 3.0 | 3.0000 4.0000 | 10 | mina1111 | 5 | 6 | 4 + 3 + 2 + 4 + 5 | 18/5 = 3.6 | 3.6000 4.5000 | 11 | mina1111 | 0 | 7 | 3 + 2 + 4 + 5 + 0 | 14/5 = 2.8 | 2.8000 3.0000 | 12 | mina1111 | 1 | 8 | 2 + 4 + 5 + 0 + 1 | 12/5 = 2.4 | 2.4000 2.5000 | 13 | mina1111 | 1 | 9 | 4 + 5 + 0 + 1 + 1 | 11/5 = 2.2 | 2.2000 2.2000 +-------+----------+---------+----------+-------------------+-----------------+ Thank you sir !
  16. Hello Guru Barand ! While the result table is great it does not produce the values I want. I wanted that this table be considered as the complete and only table for which the rolling averages needed to be found. So for your result table the values that I was looking for in the av5 columns should be as below. (I have changed the av5 values that I am looking for) +-------+----------+---------+----------+--------+ | recno | user | v_score | reccount | av5 | +-------+----------+---------+----------+--------+ | 9 | mina1111 | 4 | 5 | 4.0000 | | 10 | mina1111 | 5 | 6 | 4.5000 | | 11 | mina1111 | 0 | 7 | 3.0000 | | 12 | mina1111 | 1 | 8 | 2.5000 | | 13 | mina1111 | 1 | 9 | 2.2000 | +-------+----------+---------+----------+--------+ The following query gives me the table I want but since it is a temp table, I am unable to open it again for creating the averages. create temporary table mina1111_a Select * from ( select a.RecNo , a.User , a.V_Score from ajoo as a where User = 'mina1111' ORDER BY RecNo DESC LIMIT 5)sub Order by RecNo ASC; It gives on my table the following values:- +-------+--------------+------------+ | RecNo | User | V_Score | +-------+--------------+------------+ | 10 | mina1111 | 5 | | 11 | mina1111 | 0 | | 13 | mina1111 | 1 | | 14 | mina1111 | 1 | | 15 | mina1111 | 1 | +-------+--------------+------------+ But I am unable to use the table to get the averages. It gives the can'r reopen table error. Thanks !
  17. Hi all ! i have the following table in my DB The averages are the rolling averages for 5 records at a time. If I try and get the same for only the user mina1111 using the query SELECT user.RecNo as RecNo, user.User as User, user.V_Score as V_Score, avg(user_past.V_Score) as Average FROM user JOIN user as user_past on user_past.RecNo between user.RecNo-4 AND user.RecNo WHERE user.User = 'mina1111' GROUP by RecNo, V_Score; I get the following :- The averages go all haywire. It uses the values in the original table to calculate these, hence the funny values. So how can I get the correct values like this was the table with original values. Also how can I get the values of say only the last 5 values, considering those were the only values / rows in the table. i.e. the rolling avgs of Thanks all !
  18. Hi all ! is there a difference between an array of arrays as rs1 = [ [1,5,6,7,8,9], [ 2,7,6,5,4,3], [3,12,13,14,15,16] ]; and another formed as below as var rs1 = "1,5,6,7,8,9 2,7,6,5,4,3 3,12,13,14,15,16"; rs1 = rs1.split(" "); //alert(rs1[0]); //alert(rs1[1]); //alert(rs1[2]); //alert(rs1.length); if so, can someone explain what the difference is. Thank you !
  19. Hi ! I have a working fiddle here : https://jsfiddle.net/zswrd5oh/ While it works great for the 1st pass, (a table of 2 - 1st 9 even values ) the 2nd pass, though it works through it and gives the wanted result ( table of 3), is still flawed, in that it generated extra return key codes thereby upsetting the code logic and generating error conditions ( red boxes). I know its a bit difficult to explain but can easily be figured if the fiddle is run twice using the ready button. I have set alerts which are different in the 2 cases. Also if run in the browser, the console.log shows how the keys are registered by the program differently in the 2 passes. Ideally it would be best if the 2nd pass runs just like the first pass did. Would be grateful for any help to resolve this. Thanks !
  20. OK, I managed to rectify it though i still do not understand why it's fixed by using keyup event handler in place of keypress. keydown also gives the same problem as keypress. It would be great if you can explain it. Thanks !
  21. Hi, @cyberRoot : Thanks for the response. Yes I am / was using the keypress event. @Guru Barand: My code at the juncture I put this question was as below: // each input element has a unique id = 'result_1', 'result_2' and so on. m=1; myResult = $('#result_'+m); ansUp = ['5','11','18','26'...]; $('input[type=text]').prop("disabled", true); // console.log(myResult); myResult.prop('disabled',false); myResult.val(0); myResult.select(); myResult.addClass('yellow'); while(m < 9){ myResult.keypress(function(e) { if (e.keyCode === 13) { myval = myResult.val(); if(myval == ansUp[m-1]) { myResult.addClass('green'); myResult.prop('disabled',true); m++; myResult = $('#result_'+m); myResult.prop('disabled',false); myResult.addClass('yellow'); myResult.val(0); myResult.select(); return true; } else { myResult.addClass('red'); myResult.select(); return false; } } }) } I thought the while loop would work but then obviously that was incorrect. So i removed the while loop and thought I should add myResult.keypress(function(e) {.... } // just before return true. but that made it cyclic and that too was not great. I was missing the idea of a common class changing event which you were kind enough to show me in your code. Now I have it working for the most, the only issue is that the enter key needs to be pressed twice before the event is registered which is very odd. Here is the final code which needs me to press the enter key twice. I suspect it has something to do with the '0' value that I put into the input box and then put the focus on that for the ease of the user. Here's how it stands now: $(".ui").change(function(){ myResult.keypress(function(e) { if (e.keyCode === 13) { myval = myResult.val(); if(myval == ansUp[m-1]) { if(myResult.hasClass('red')){ myResult.removeClass('red'); } myResult.addClass('green'); myResult.prop('disabled',true); m++; myResult = $('#result_'+m); myResult.prop('disabled',false); myResult.addClass('yellow'); myResult.val(0); myResult.select(); } else { myResult.addClass('red'); myResult.select(); } } }) }) Please help ! Thanks loads Guru Barand and cyberRoot !
  22. Hi, I need to collect user inputs in input boxes. All boxes are disabled except the one which awaits input. once an input is made and satisfies a certain criteria, the next input box in the sequence is enabled and awaits input. Thus i need my code to cycle a certain section of my code and collect all inputs which is like saying it needs to do nothing as it waits for the user input. I cannot put this in any loop because it freezes the loop. The only way I can think of accomplishing this is by using a setTimeout and awaiting for keypress during that time, collecting input, breaking out of the loop, and targetting the next inputbox in the setTimeout function till all input is collected. I just wish to know if anyone has a better idea to do this task. Thanks !
  23. Hi ! @cyberRoot: Thanks for the additional information. I am aware that it's not supported by IE but it seems to work fine in chrome. I have never used let in for loops earlier so I simply removed the let and it works fine anyways. I have read the links you have provided and it seems that there is no advantage of using it except for the fact that it may be a bit faster since it is bound only once for all iterations. I'll look up google analytics, though i have not ever used it. Thanks ! @Maxxd : Thanks for the reply. I think all experts in the forum and really very helpful and nice without exceptions. I'll do try out things in quite detail actually before I ask. I'll keep in mind your advice. Thank you again !
  24. Hi ! @cyberRoot Thank you for that insight. Yes I am trying to avoid any inline code. After what you have pointed out, I think I will have to scrutinize my existing code as well. I think Guru Barand has implemented the addclass mechanism, you suggested in your reply already. @maxxd Thanks for replying to so many of my doubts. To both of the above, I was actually referring to this bit of code below $("input[tabindex = "+ind+"]") where I was wondering if the same functionality could be achieved using name or .class in place of tabindex. Even though it works it does seem rather ugly to use like this. ( tabindex needed to be defined before it was used. I know that the for such array of elements, the name property gets assigned an array with an inherent index value) . Only for the sake of clarification, It's because I am thinking and trying things out that I get all these questions in my head and I do like to clarify as far as possible. I do not come back with my doubts unless I have tried out things further, read and searched the net and tried to find my answers. For eg. In my last reply, I found a method to target the individual cell but came back to clarify if it was the correct method and to learn if it could be done using the name property etc. So it's not like I am asking to do it but a bit of code definitely helps clarify a lot. Thank you for the fiddle on grids. I'll study it and maybe change to do eventually like that. I do have more questions, but seriously, I am a bit scared to ask them. Yes Guru Barand is has, as always, been most helpful and generous too ! @ Guru Barand : I can't thank you enough for all your help and all that I have learnt from you. No offence to anyone please. I can only be grateful for all the help and assistance that I have received at the forum for years ! Thank you all !🙏
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.