Last active
August 29, 2015 14:05
-
-
Save Kudratullah/e1c036448c798eaa8ec5 to your computer and use it in GitHub Desktop.
SetUp Video Player For Browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* This Function Is InComplete. | |
* @param video url string; | |
* @return mixed; | |
**/ | |
//$url="https://www.youtube.com/embed/Tgb0jK143MI"; | |
//$url = 'https://www.youtube.com/embed/FblnhqYEae0'; | |
$url ="https://www.youtube.com/watch?v=Hg8Fa_EUQqY&index=23&list=PLDu39zhqv26ILpsfB1INvhqqsBvSdI6wG"; | |
//$url = 'http://vimeo.com/channels/staffpicks/97916782'; | |
//$url = 'http://vimeo.com/97916782'; | |
//$url = '//player.vimeo.com/video/97916782?title=0&byline=0&portrait=0&badge=0&color=ffffff'; | |
function video($url, $w='100%', $h='auto', $old_code_for_ie = false){ | |
if (strpos($url, 'youtube.com/embed/') > 0){ | |
$uri_type = 'yt'; | |
}elseif(strpos($url, 'youtube.com/watch?') > 0){ | |
$uri_type = 'yt'; | |
}elseif(strpos($url, 'vimeo.com/') > 0){ | |
$uri_type = 'vimeo'; | |
}else{ | |
$uri_type = 'unknown'; | |
} | |
if($uri_type == 'yt'){ | |
$yt = explode('/',$url); | |
$counter = count($yt); | |
if($counter == 5){ | |
$yt = explode('?',$yt[4])[0]; | |
}elseif($counter == 4){ | |
$yt = explode('&',explode('=',explode('=',$yt[3])[1])[0])[0]; | |
}else{ | |
return false; | |
} | |
if($old_code_for_ie == 1){ | |
$IE6 = (ereg('MSIE 6',$_SERVER['HTTP_USER_AGENT'])) ? true : false; | |
$IE7 = (ereg('MSIE 7',$_SERVER['HTTP_USER_AGENT'])) ? true : false; | |
$IE8 = (ereg('MSIE 8',$_SERVER['HTTP_USER_AGENT'])) ? true : false; | |
$IE9 = (ereg('MSIE 9',$_SERVER['HTTP_USER_AGENT'])) ? true : false; | |
if (($IE6 == 1) || ($IE7 == 1) || ($IE8 == 1) || ($IE9 == 1)) { | |
// IE Detected and IE <= 9; | |
$h = ($w/16)*9; | |
$markup = '<object class="yt_video" width="'.$w.'" height="'.$h.'"><param name="movie" value="//www.youtube.com/v/'.$yt.'?vq=hd1080&version=3&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="//www.youtube.com/v/'.$yt.'?vq=hd1080&version=3&hl=en_US" type="application/x-shockwave-flash" width="'.$w.'" height="'.$h.'" allowscriptaccess="always" allowfullscreen="true"></embed></object>'; | |
}else{ | |
// IE Not Detected or IE > 9; | |
$markup = '<iframe class="yt_video" src="//www.youtube.com/embed/'.$yt.'?vq=hd1080" allowfullscreen style="width:'.$w.';height:'.$h.'border:0;"></iframe>'; | |
} | |
}else{ | |
$markup = '<iframe class="yt_video" src="//www.youtube.com/embed/'.$yt.'?vq=hd1080" allowfullscreen style="width:'.$w.';height:'.$h.'border:0;"></iframe>'; | |
} | |
return $markup; | |
}elseif($uri_type == 'vimeo'){ | |
$vimeo = explode('/',$url); | |
$counter = count($vimeo); | |
if($counter == 6){ | |
$vimeo = $vimeo[5]; | |
}elseif($counter == 5){ | |
$vimeo = explode('?',$vimeo[4])[0]; | |
}elseif($counter == 4){ | |
$vimeo = $vimeo[3]; | |
}else{ | |
return false; | |
} | |
if($old_code_for_ie == 1){ | |
$IE6 = (ereg('MSIE 6',$_SERVER['HTTP_USER_AGENT'])) ? true : false; | |
$IE7 = (ereg('MSIE 7',$_SERVER['HTTP_USER_AGENT'])) ? true : false; | |
$IE8 = (ereg('MSIE 8',$_SERVER['HTTP_USER_AGENT'])) ? true : false; | |
$IE9 = (ereg('MSIE 9',$_SERVER['HTTP_USER_AGENT'])) ? true : false; | |
if (($IE6 == 1) || ($IE7 == 1) || ($IE8 == 1) || ($IE9 == 1)) { | |
// IE Detected and IE <= 9; | |
$h = ($w/16)*9; | |
$markup = '<!-- This version of the embed code is no longer supported. Learn more: https://vimeo.com/s/tnm --> <object width="'.$w.'" height="'.$h.'"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=97916782&force_embed=1&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=ffffff&fullscreen=1&autoplay=0&loop=0" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=97916782&force_embed=1&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=ffffff&fullscreen=1&autoplay=0&loop=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="'.$w.'" height="'.$h.'"></embed></object>'; | |
}else{ | |
// IE Not Detected or IE > 9; | |
$markup = '<iframe src="//player.vimeo.com/video/'.$vimeo.'?title=0&byline=0&portrait=0&badge=0&color=ffffff" webkitallowfullscreen mozallowfullscreen allowfullscreen style="width:'.$w.';height:'.$h.'border:0;"></iframe>'; | |
} | |
}else{ | |
$markup = '<iframe src="//player.vimeo.com/video/'.$vimeo.'?title=0&byline=0&portrait=0&badge=0&color=ffffff" webkitallowfullscreen mozallowfullscreen allowfullscreen style="width:'.$w.';height:'.$h.'border:0;"></iframe>'; | |
} | |
return $markup; | |
}else{ | |
return false; | |
} | |
} | |
echo "<pre>"; | |
var_dump(video($url)); | |
echo "</pre>"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment