Created
August 8, 2011 20:19
-
-
Save Dakwamine/1132627 to your computer and use it in GitHub Desktop.
*Static* Youtube and Blip players
This file contains 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 | |
/** | |
* | |
* Creates validable XHTML Youtube or Blip players, compatible with Flash and iPhone/iPad | |
* | |
* If you are HTML4/5, you can simply use default Youtube and Blip <iframe> | |
* instead of this file (although these seems to not correctly validate on W3 validator). | |
* | |
* PHP 5.3.0 (but you can adapt the code following your needs) | |
* | |
*/ | |
class articleobject | |
{ | |
public static function YoutubePlayer($id, $width = 780, $height = 440) | |
{ | |
$width = (int)$width; | |
$height = (int)$height; | |
if(strstr($_SERVER['HTTP_USER_AGENT'], 'iPod') === FALSE | |
&& strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone') === FALSE | |
&& strstr($_SERVER['HTTP_USER_AGENT'], 'iPad') === FALSE) | |
{ | |
// If the video is not watched from iPod, iPhone or iPad | |
// Adds 30 to $height to compensate command bar height | |
$height += 30; | |
} | |
$string = | |
<<<EOT | |
<object type="application/x-shockwave-flash" | |
width="$width" | |
height="$height" | |
data="http://www.youtube.com/v/$id?version=3"> | |
<param name="movie" value="http://www.youtube.com/v/$id?version=3"/> | |
<param name="allowScriptAccess" value="always"/> | |
<param name="allowFullScreen" value="true"/> | |
</object> | |
EOT; | |
return $string; | |
} | |
public static function BlipPlayer($id, $width = 780, $height = 440) | |
{ | |
$width = (int)$width; | |
$height = (int)$height; | |
// iPhone, iPod, iPad | |
if(strstr($_SERVER['HTTP_USER_AGENT'], 'iPod') | |
|| strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone') | |
|| strstr($_SERVER['HTTP_USER_AGENT'], 'iPad')) | |
{ | |
$string = | |
<<<EOT | |
<video src="http://blip.tv//play/$id.m4v" | |
width="$width" | |
height="$height" allowfullscreen controls x-webkit-airplay="allow" airplay="allow"></video> | |
EOT; | |
} | |
else | |
{ | |
// Adds 30 to $height to compensate command bar height | |
$height += 30; | |
$string = | |
<<<EOT | |
<object type="application/x-shockwave-flash" | |
width="$width" | |
height="$height" | |
data="http://blip.tv/play/$id"> | |
<param name="movie" value="http://blip.tv/play/$id"/> | |
<param name="allowScriptAccess" value="always"/> | |
<param name="allowFullScreen" value="true"/> | |
</object> | |
EOT; | |
} | |
return $string; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment