Skip to content

Instantly share code, notes, and snippets.

@Dakwamine
Created August 8, 2011 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dakwamine/1132627 to your computer and use it in GitHub Desktop.
Save Dakwamine/1132627 to your computer and use it in GitHub Desktop.
*Static* Youtube and Blip players
<?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