Not so long ago, I updated my browser-aware player code to check for the presence of a stream. Recently, it’s come to light that Internet Explorer 9 doesn’t play nice with this particular snippet, because in IE9, the Javascript engine is rather brain-damaged when it comes to cross-site requests. In order to deal with this properly, we must alter the way we query the server for the presence of a stream:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | console.log( "Starting stream Check" ); if (is_ie9) { console.log ( "Using XDR because IE9 is stupid" ); streamcheckXDR(); setInterval( function (){streamcheckXDR()},10000); } else { streamcheck(); setInterval( function (){streamcheck()},10000); } function streamcheckXDR() { console.log( "Starting XDR" ); xdr = new XDomainRequest(); if (xdr) { xdr.onerror = function (){ console.log( "XDR Error" ); }; xdr.onload = function (){ startPlayer(xdr.responseText, "XDR" ); }; url = "http://" +streamer+ ":8086/streamcheck?stream=" +stream; xdr.open( "get" ,url); xdr.send(); } else { console.log( "Failed to create XDR object" ); } } function startPlayer(result,mode){ // for some inexplicable reason, running "Boolean" on the XDR output doesn't work // so we have to call the function and tell it if we're dealing with XDR data or AJAX data. if (mode == "XDR" ) { if (result === "true" ) { curstatus = true ;} if (result === "false" ) { curstatus = false ;} } else { curstatus = Boolean(result); } //console.log("Result: "+result); //console.log("Previous: "+prevstatus); //console.log("Current: "+curstatus); if (curstatus == prevstatus) { //console.log("No Change"); } else { if (curstatus) { if (is_iphone || is_ipad || is_ipod) { iOSPlayer( "videoframe" ,plwd,plht,server,stream);} else if (is_blackberry) { rtspPlayer( "videoframe" ,plwd,plht,server,stream+ '_+240p' );} else { flashPlayer( "videoframe" ,plwd,plht,server,stream); } console.log( "Changed from false to true" ); } else { var vframe=document.getElementById( "videoframe" ) if (is_iphone || is_ipad || is_ipod || is_blackberry) { } else { jwplayer( "videoframe" ).remove(); } vframe.innerHTML = '<IMG SRC="image.png" WIDTH="' +plwd+ '" HEIGHT="' +plht+ '">' ; console.log( "Changed from true to false" ); } } prevstatus = curstatus; } function streamcheck() { console.log( "Starting AJAX" ); $.ajax({ dataType: "json" , contentType: "text/plain" , type: "GET" , url: "http://" +streamer+ ":8086/streamcheck?stream=" +stream, error: function (XMLHttpRequest, textStatus, errorThrown) { console.log( 'AJAX Failure:' + textStatus+ ':' +errorThrown); //some stuff on failure }, success: function (result){startPlayer(result)} }); } |
Hi Ian, silly question, does this replace lines 38-70 on Browser-aware player code, revisited again (http://blog.ianbeyer.com/2012/10/29/browser-aware-player-code-revisited-again/)