<?php
// Play Video in Various Browsers - RJM Programming - October, 2014

$iscalled = "";

if (isset($_GET['autostart'])) {
$iscalled = "y";
$astart = urldecode($_GET['autostart']);
} else if (isset($_POST['autostart'])) {
$iscalled = "y";
$astart = urldecode($_POST['autostart']);
} else {
$astart = ' autostart=1 ';
}
if (isset($_GET['loop'])) {
$iscalled = "y";
$aloop = urldecode($_GET['loop']);
} else if (isset($_POST['loop'])) {
$iscalled = "y";
$aloop = urldecode($_POST['loop']);
} else {
$aloop = ' loop=true ';
}
if (isset($_GET['hidden'])) {
$iscalled = "y";
$ahidden = urldecode($_GET['hidden']);
} else if (isset($_POST['hidden'])) {
$iscalled = "y";
$ahidden = urldecode($_POST['hidden']);
} else {
$ahidden = ' hidden=true ';
}
if (isset($_GET['controls'])) {
$iscalled = "y";
$bcontrols = urldecode($_GET['controls']);
} else if (isset($_POST['controls'])) {
$iscalled = "y";
$bcontrols = urldecode($_POST['controls']);
} else {
$bcontrols = 'controls=controls ';
}
if (isset($_GET['autoplay'])) {
$iscalled = "y";
$bautoplay = urldecode($_GET['autoplay']);
} else if ($iscalled != "")  {
$iscalled = "y";
$bautoplay = urldecode($_POST['autoplay']);
} else {
$bautoplay = ' autoplay=autoplay ';
}
if (isset($_GET['bloop'])) {
$iscalled = "y";
$bloop = urldecode($_GET['bloop']);
} else if (isset($_POST['bloop'])) {
$iscalled = "y";
$bloop = urldecode($_POST['bloop']);
} else {
$bloop = ' loop=loop ';
}

if (isset($_GET['domain'])) {
$iscalled = "y";
$ivd =  urldecode($_GET['domain']);
} else if (isset($_POST['domain'])) {
$iscalled = "y";
$ivd =  urldecode($_POST['domain']);
} else {
$ivd = "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . "" . str_replace("?" . $_SERVER['QUERY_STRING'], "", str_replace("video_generic.php", "", $_SERVER['REQUEST_URI']));  // 'http://www.rjmprogramming.com.au/PHP/';
}
if (isset($_GET['path'])) {
$iscalled = "y";
$ivfp =  urldecode($_GET['path']);
} else if (isset($_POST['path'])) {
$iscalled = "y";
$ivfp =  urldecode($_POST['path']);
} else {
$ivfp = 'videos/';
}
if (isset($_GET['filename'])) {
$iscalled = "y";
$ivn =  urldecode($_GET['filename']);
} else if (isset($_POST['filename'])) {
$iscalled = "y";
$ivn =  urldecode($_POST['filename']);
} else {
$ivn = 'GoToMeeting';  //'Nala_HideAndSeek';
}
$ivdir = $ivd . $ivfp;
$ivfilene = $ivdir . $ivn;
$ivfile = $ivfilene . '.mp4';

$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
if (strpos($ua, "msie 8") !== false || 
    strpos($ua, "msie 7") !== false || 
    strpos($ua, "msie 6") !== false) {
      $huh = file_get_contents($ivfile);
 	  header('Content-type: video/mp4');
 	  echo $huh;
      exit;
}

?>

<!DOCTYPE html>
<html>
<head>
<?php echo '<title>Play Video in Various Browsers</title>'; ?>
<script type="text/javascript">

var isoff=0;

function iFrameFunction() {
 var siss=document.getElementById("video"); 
 if (isoff == 0) { 
  isoff = siss.volume; 
  siss.volume=0;
 } else { 
  siss.volume=isoff;
  isoff = 0;
 }
}

</script>



</head>
<body style="background-color:yellow;">
<div align="center" id="vform">
<h1 align="center">Video Play</h1>
<?php echo "\n" . '<form id="myvform" name="myvform" action="' . $_SERVER["REQUEST_URI"] . '" method="POST">' . "\n"; ?>
<table align="center" border=3 cellpadding=5 cellspacing=5 style="background-color:pink;"><tr><td>
<?php echo "<a target=_blank title='Video autoplay' href='http://www.w3schools.com/tags/att_video_autoplay.asp'>Autoplay</a>: <input type='text' id='autoplay' name='autoplay' value='" . $bautoplay . "'></input>\n"; ?>
</td><td>
<?php echo "<a target=_blank title='Video controls' href='http://www.w3schools.com/tags/att_video_controls.asp'>Controls</a>: <input type='text' id='controls' name='controls' value='" . $bcontrols . "'></input>\n"; ?>
</td><td>
<?php echo "<a target=_blank title='Video loop' href='http://www.w3schools.com/tags/att_video_loop.asp'>Loop</a>: <input type='text' id='bloop' name='bloop' value='" . $bloop . "'></input>\n"; ?>
</td></tr><tr style=background-color:orange;><td style=width:55%;>
<?php echo "Base URL: <input style=width:75%; type='text' id='domain' name='domain' value='" . $ivd . "'></input>\n"; ?>
</td><td>
<?php echo "Subdirectory: <input type='text' id='path' name='path' value='" . $ivfp . "'></input>\n"; ?>
</td><td>
<?php echo "Filename.ogv/.mp4/.webm: <input title='You may need .ogv/.mp4/.webm ... do you need http://www.online-convert.com/ ?' type='text' id='filename' name='filename' value='" . $ivn . "'></input>\n"; ?>
</td></tr><tr><td>
<?php echo "<a target=_blank title='Embed autostart' href='http://www.htmlcodetutorial.com/embeddedobjects/_EMBED_AUTOSTART.html'>Autostart</a>: <input type='text' id='autostart' name='autostart' value='" . $astart . "'></input>\n"; ?>
</td><td>
<?php echo "<a target=_blank title='Embed loop' href='http://www.htmlcodetutorial.com/embeddedobjects/_EMBED_LOOP.html'>Loop</a>: <input type='text' id='loop' name='loop' value='" . $aloop . "'></input>\n"; ?>
</td><td>
<?php echo "<a target=_blank title='Embed hidden' href='http://www.htmlcodetutorial.com/embeddedobjects/_EMBED_HIDDEN.html'>Hidden</a>: <input type='text' id='hidden' name='hidden' value='" . $ahidden . "'></input>\n"; ?>
</td></tr></table>
<br><br><input align="center" type='submit' name='submit' id='submit' value='Play'></input><br><br>
</form>
</div>
<div align="center" id="player" <?php if ($iscalled == "")  echo ' style="display:none;" ';  ?>>
<?php  if ($iscalled != "")  echo "<video id=\"video\"  " . $bautoplay . ' ' . $bcontrols . ' ' . $bloop . ' style=height:90%;>'; ?>
<?php  if ($iscalled != "")  echo '<source src="' . $ivfilene . '.ogv" type="video/ogg" /> '; ?>
<?php
    $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
    // you can add different browsers with the same way ..
    if (strpos($ua, "msie") !== false || strpos($ua, "windows ") !== false) {
       if ($iscalled != "")  echo '<source src="' . $ivfilene . '.mp4" type="video/mp4" />'."\n";
    } else if (strpos($ua, "safari") !== false)  {
       if ($iscalled != "")  echo '<source src="' . $ivfilene . '.mp4" type="video/mp4" />'."\n";
       if ($iscalled != "")  echo '<embed src="' . $ivfilene . '.mp4"  ' . $ahidden . ' ' . $aloop . ' ' . $astart . '></embed>'."\n";
    } else if (strpos($ua, "mozilla") !== false) {
       if ($iscalled != "")  echo '<source src="' . $ivfilene . '.webm" type="video/webm" />'."\n";
       if ($iscalled != "")  echo str_replace(".webm\" ", ".webm\"  type='video/webm; codecs=\"vp8, vorbis\"' ", '<embed src="' . $ivfilene . '.webm"  ' . $ahidden . ' ' . $aloop . ' ' . $astart . '></embed>')."\n";
    } else {
       if ($iscalled != "")  echo '<source src="' . $ivfilene . '.mp4" type="video/mp4" />'."\n";
       if ($iscalled != "")  echo '<embed src="' . $ivfilene . '.mp4"  ' . $ahidden . ' ' . $aloop . ' ' . $astart . '></embed>'."\n";
    }
?>
<?php  if ($iscalled != "")  echo '</video>' . "\n"; ?>
<?php  if ($iscalled != "")  echo "&nbsp;&nbsp;<a href='#' onclick='iFrameFunction();'>Toggle</a>\n"; ?>
</div></body>
</html>    
