最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Embed YouTube videos with fallback solution for corporate proxies - Stack Overflow

programmeradmin0浏览0评论

I am wondering whether any of you have ever e accross a solution/function that allows embedding YouTube videos with a fallback solution where an alternative video source is selected if YouTube videos - and the videos only! - are blocked.

One of our corporate clients have access to the web via a proxy server that weeds out flash content served form YouTube. More specifically anything served from ytimg is blocked. Since their website is quite heavy on product videos they find it annoying to boot that clients can watch videos on their site while their own staff can't.

Any suggestions?

I am wondering whether any of you have ever e accross a solution/function that allows embedding YouTube videos with a fallback solution where an alternative video source is selected if YouTube videos - and the videos only! - are blocked.

One of our corporate clients have access to the web via a proxy server that weeds out flash content served form YouTube. More specifically anything served from ytimg. is blocked. Since their website is quite heavy on product videos they find it annoying to boot that clients can watch videos on their site while their own staff can't.

Any suggestions?

Share Improve this question asked Dec 7, 2011 at 21:06 TommTomm 2,1421 gold badge15 silver badges20 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

You should try to make an Ajax request to something hosted in youTube, i would say something like this:

function check_youtube() {
  $.ajax({
    type: 'GET',
    dataType: 'json',
    url: URL_ON_YOUTUBE,
    timeout: 5000,
    success: function(data, textStatus ){
       alert('Woot, Cat videos on the way!');
    },
    error: function(xhr, textStatus, errorThrown){
       alert('Ooops, You suck, proxy blocking your way');
    }
  });
}

It should be clarified that Youtube's Flash player is a different thing than the FLV or MP4 file that it plays. While the Flash player may be served from *.ytimg., the streams themselves e from hosts like "o-o.preferred.lga15s18.v2.lscache6.c.youtube.".

If your client is blocking the former, then you can't use Youtube to get at the videos. My approach would be to launch your videos from a page that has some sort of automation to recognize your client's IP address range and load up your own copy of jwplayer or flowplayer or somesuch.

While you could do this browser-side using something like an ajax call, you still run the risk of overly-conservative corporate IT disabling javascript. (I've seen it happen. It's not pretty.) Putting the "smarts" on your server leaves you in control, though of course it means you need to know ahead of time what the restrictions are, so that you can adjust for them.

When building the page, you could test for a working connection to ytimg., and update the source of the iframe you're using for display accordingly...

<iframe src="<?php

//Use a dummy (but valid) ytimg. url to check for ytimg availability...
$h = get_headers('http://s.ytimg./yt/swfbin/watch_as3-vflZzp2iQ.swf');

//If ytimg. isn't available...
if (stristr($h[0], '200') == FALSE)
{ ?>

    <!--Alt URL-->

<?php

//Otherwise, if ytimg. is available...
} else { ?>

    <!--YouTube URL-->

<?php } ?> "></iframe>

Alternatively, you could politely suggest that your client not be such a hard-ass and allow their employees the occasional YouTube break at work.

EDIT Just kidding, I'm an idiot. Use camilo_u's suggestion above.

发布评论

评论列表(0)

  1. 暂无评论