Jump to content

justinh

Members
  • Content Count

    28
  • Joined

  • Last visited

Community Reputation

1 Neutral

About justinh

  • Rank
    Newbie
  1. You're right. I forgot about the timeout in the case of the server being off. My experience is it takes 21s to return an error. I need to find a way for the head request to abort after so much time (less than 21s). Then that might work. It's not elegant, but it might serve the purpose.
  2. Checking for the header may work. Ajax is dependent on jQuery, correct? Is it possible to do the same thing with the native Fetch API? Would I have to check for a specific header property (like status) or if there is no header it would return false and I could just use that? The server is not always streaming. The server is running only when it is streaming.
  3. Yes, I've been using the browser's dev tools; that's how I discovered some of the findings above. The stream originate from my domain, it is not an arbitrary URL. JS can work, as described above, but it is just not reliable. BTW, I tried many event handlers, but I mentioned what I found to do something useful for me. The ended event would be useful when the stream is ends of course, either because it is at the end or because of a network interruption onerror also. But, the scenario is not that simple. The problem is whatever I use has to account for any situation, this it why it has to be like a monitor. The stream could be on or off any time (before or after the page is loaded, interrupted and recovered, etc.).
  4. I confirmed that event handlers don't continuously monitor changes. This is so frustrating. <audio id="myAudio" oncanplay="myTimer0()" onprogress="myTimer00()" onerror="myTimer000()" controls> If stream is on, upon page load onprogress fires. Stop the stream (at server). Reload the page and onprogress still fires. This is the same behavior as with the original methods - I have to clear the cache to get a true reading!
  5. Thanks. I found that onstalled fires if the stream is not available upon page load. It also appears that the audio tag starts looking for the source as soon as the page loads, instead of when the user hits play. Is that correct? That might explain the disconnect between me and justsomeguy 😟 Here's what I think to be the problem with theses events. the page loads - stream is not available, JS is used to show error on page 10 seconds later the stream becomes available (the sever is now sending a stream) Are the events going to be in effect now? Will the on oncanplay event now fire? If so, JS could now be used to show an updated status on the page
  6. Right, so what causes the download to start? Wouldn't the user have to hit play for the download to even start? (To be sure, audio will not start playing by itself, the user will have to initiate playback.) In my case, if the server opens a connection, there is data in the stream. (Can a stream actually have empty data??) Thanks, Ingolme. Your explanation of the event is better than MDN's.
  7. Well, I just want to know if the audio is available. It doesn't matter if it is playing (in my browser). It's like checking for a PNG file on the server; it doesn't have to be loaded on my page to be available for download, it just has to exist, so I can call it when I want it. The audio (if available) won't play until I hit play on the player. I'm sorry if I'm using non-standard verbiage, but it is the only way I know. Yes, canplay looks like it might be suitable. So, to use it, my code would look something like: var v = document.getElementsByTagName("audio")[0]; v.addEventListener("canplay", myfunction()); 1) When the page loads, this event handler will automatically start? 2) The event handler will, on it's own, just continue to check the event forever? For #2, this is my confusion. The audio could be available, but it doesn't push itself to the page, does it? If it doesn't, then how would the event be triggered? Upon page load, does the 'page' try to hook up to the stream or is it ignorant of the stream until I hit play? I do appreciate the help.
  8. No. I need to DETECT if the stream exists or not (is it available to play?). I don't care if the browser is actually playing it, that is not the issue. I'm not sure if any of the Media events will do what I need, because it looks like the user has to interact with the page at some time or another for any of the events to trigger. I'll have to try, after I figure out how to use event handlers. :-)
  9. Yes, active = stream is live (playing). But is there an event handler to detect when the stream is turned and turned off? Something equivalent to what I have now?
  10. I'm trying to check for an audio stream, to see if it is active. I found two methods, .networkState and .readyState, that work against an audio tag or an Audio() object. Things look okay when the stream is off and never been listened to (not in browser cache). I have both methods being executed every 4s to catch any change in the stream. The trouble is that I can't get either method to correctly update the status of the stream once it has changed, that is, from off to on or on to off. I have to refresh to the page to get a real update. Then, after you've listened to the stream and it is cached, it always shows as 'on'. (The counters are updating, so I know the page is updating, but the stream detection is not updating dynamically.) Why wouldn't the status change when the stream changes? Is there a way to force a check against the actual object instead of the cached object? (excuse my code - I quickly chunked this together and I am a newbie) (I went thru all the below to test the diff methods and for debugging, so you can look at only function to get the drift) <audio id="myAudio" controls> <source src="http://myserver.com:8080/live.mp3" type="audio/mpeg"> Your browser does not support the audio element. </audio> <!-- BEGINS: AUTO-GENERATED MUSES RADIO PLAYER CODE --> <script src="https://myserver.com/stream/mrp.js"></script> <script> MRP.insert({ 'url':'http://myserver.com:8080/live.mp3', [ . . .] }); </script> <!-- ENDS: AUTO-GENERATED MUSES RADIO PLAYER CODE --> <!-- this is what does not update correctly on the page --> <p>StreamN0 is: <span id="netstate">OFFLINE</span></p> <p>StreamN1 is: <span id="netstate1">OFFLINE</span></p> <p>StreamR0 is: <span id="readystate">OFFLINE</span></p> <p>StreamR1 is: <span id="readystate1">OFFLINE</span></p> <script> var myTimerVar = setInterval(myTimer, 4000); var myTimerVar1 = setInterval(myTimer1, 4000); var myFunctionVar = setInterval(myFunction, 4000); var myFunctionVar1 = setInterval(myFunction1, 4000); var aud = new Audio('http://myserver.com:8080/live.mp3'); var n0 = 0; var n1 = 0; var r0 = 0; var r1 = 0; function myTimer() { var acheck = document.getElementById("myAudio").networkState; if (acheck == 2) { //(acheck == 2 || acheck == 3) document.getElementById("netstate").innerHTML = "buffering " + acheck + " - " + n0++; document.getElementById("netstate").style.backgroundColor = "yellow"; } else if (acheck == 3) { document.getElementById("netstate").innerHTML = "OFFLINE " + acheck + " - " + n0++; document.getElementById("netstate").style.backgroundColor = "yellow"; } else if (acheck == 1) { // works in local env but says online when on server; not reliable document.getElementById("netstate").innerHTML = "ONLINE " + acheck + " - " + n0++; document.getElementById("netstate").style.backgroundColor = "MediumSeaGreen"; } else { document.getElementById("netstate").innerHTML = "unknown " + acheck + " - " + n0++; } } function myTimer1() { var acheck1 = aud.networkState; if (acheck1 == 2) { document.getElementById("netstate1").innerHTML = "buffering " + acheck1 + " - " + n1++; document.getElementById("netstate1").style.backgroundColor = "yellow"; } else if (acheck1 == 3) { document.getElementById("netstate1").innerHTML = "OFFLINE " + acheck1 + " - " + n1++; document.getElementById("netstate1").style.backgroundColor = "yellow"; } else if (acheck1 == 1) { document.getElementById("netstate1").innerHTML = "ONLINE " + acheck1 + " - " + n1++; document.getElementById("netstate1").style.backgroundColor = "MediumSeaGreen"; } else { document.getElementById("netstate1").innerHTML = "unknown " + acheck1 + " - " + n1++; } } function myFunction() { var x = document.getElementById("myAudio").readyState; if (x == 0) { document.getElementById("readystate").innerHTML = "OFFLINE " + x + " - " + r0++; document.getElementById("readystate").style.backgroundColor = "yellow"; } else if (x == 4) { document.getElementById("readystate").innerHTML = "ONLINE " + x + " - " + r0++; document.getElementById("readystate").style.backgroundColor = "MediumSeaGreen"; } else { document.getElementById("readystate").innerHTML = "unknown " + x + " - " + r0++; } } function myFunction1() { var x1 = aud.readyState; if (x1 == 0) { document.getElementById("readystate1").innerHTML = "OFFLINE " + x1 + " - " + r1++; document.getElementById("readystate1").style.backgroundColor = "yellow"; } else if (x1 == 4) { document.getElementById("readystate1").innerHTML = "ONLINE " + x1 + " - " + r1++; document.getElementById("readystate1").style.backgroundColor = "MediumSeaGreen"; } else { document.getElementById("readystate1").innerHTML = "unknown " + x1 + " - " + r1++; } } </script> I'd appreciate any help.
  11. Is it possible to change/modify a loaded web page automatically with PHP? I want to load a page, then have PHP do something, then update the page with the new information (like change a text string).
  12. justinh

    header info query

    EDIT: I found a config modules dialog in UniServer where I could toggle on php_openSSL.dll, and that enabled the HTTPS stream. Now I get success in my local env! Without this config interface I don't know how this would be configured (or why it is not out-of-the-box) - - - - I tried running my PHP file on my local stack (WAMP, Uniform Server Zero). I was getting a bunch of errors. php.ini shows allow_url_fopen = on. I was testing with HTTPS URLs, and I finally discovered that my local PHP does not have the HTTPS stream registered, but my remote PHP does have it registered. I can't figure out what is controlling the registration of streams or how to add a stream. Anyone know? Warning: get_headers(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? Registered PHP Streams php, file, glob, data, http, ftp, zip, compress.zlib, phar PS Sorry, dsonesuk, I was getting .htaccess and httpd.conf confused. Thanks.
  13. justinh

    header info query

    It appears my setting for "allow_url_fopen" in my file's folder php.ini was not being honored; it wouldn't work even if I set it in the PHP file, even if I set the X-frame-options header. I had to set "allow_url_fopen" in the site root's php.ini! I thought the local (to the file) php.ini would be in effect. Is there someway to make that work, or am I totally washed up about that? Maybe I am thinking about htaccess? Man, I fought this for two days! Thanks so much, everyone. I'm sure I'll be back after I get to the next step :-)
  14. justinh

    header info query

    Var_dump of the get_headers is showing " bool(false) ". Why would it be false? What I found out about file_get_contents is that it works with relative paths (e.g., '../myfile.txt') but not with an absolute path (e.g., 'https://myserver.com/myfile.txt'). I this same problem with getimagesize, file_exists, and fopen (though PHP.net shows an example with absolute path). Why won't absolute paths work on my server when supposedly they are supposed to work with these functions? I can't use relative paths because the file I'm checking for is on a subdomain that is on another server. And I can't rely on response headers, so I really like the idea of just checking for a file.
  15. justinh

    header info query

    Hi, I've been trying to get response header information and some PHP functions are not returning anything. I'm sure I am missing something fundamental, but I don't know why I'm not getting anything after I browse to header.php (which contains all of the below) on my remote server. From https://secure.php.net/manual/en/function.get-headers.php, example 1: $url = 'https://yahoo.com'; print_r(get_headers($url)); print_r(get_headers($url, 1)); It shows nothing on the page. From https://php.net/manual/en/function.get-headers.php#97684: function get_http_response_code($theURL) { //https://php.net/manual/en/function.get-headers.php#97684 $headers = get_headers($theURL); return substr($headers[0], 9, 3); } echo get_http_response_code("https://yahoo.com"); It shows nothing on the page. From https://php.net/manual/en/function.get-headers.php#112652: function get_http_response_code($theURL) { $headers = get_headers($theURL); return substr($headers[0], 9, 3); } if(intval(get_http_response_code('filename.jpg')) < 400){ echo "file was found"; } else { echo "no file found"; } It shows nothing on the page. From https://secure.php.net/reserved.variables.server, example 1: echo ($_SERVER["yahoo.com"]); It shows nothing on the page. From https://secure.php.net/manual/en/reserved.variables.httpresponseheader.php: function get_contents() { file_get_contents("https://berean-biblechurch.org/rss/rss.xml"); var_dump($http_response_header); } get_contents(); var_dump($http_response_header); It shows "NULL". I'd appreciate any help. Justin
×