Advertisement
Guest User

avia_html5_video_embed

a guest
May 7th, 2018
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. if(!function_exists('avia_html5_video_embed'))
  2. {
  3.     /**
  4.      * Creates HTML 5 output and also prepares flash fallback for a video of choice
  5.      * @return string HTML5 video element
  6.      */
  7.     function avia_html5_video_embed($path, $image = "", $types = array('webm' => 'type="video/webm"', 'mp4' => 'type="video/mp4"', 'ogv' => 'type="video/ogg"'), $attributes)
  8.     {
  9.  
  10.         preg_match("!^(.+?)(?:\.([^.]+))?$!", $path, $path_split);
  11.  
  12.         $output = "";
  13.         if(isset($path_split[1]))
  14.         {
  15.             if(!$image && avia_is_200($path_split[1].'.jpg'))
  16.             {
  17.                 $image = 'poster="'.$path_split[1].'.jpg"'; //poster image isnt accepted by the player currently, waiting for bugfix
  18.             }
  19.  
  20.             $autoplay = $attributes['autoplay'] == 1 ? 'autoplay' : '';
  21.             $loop = $attributes['loop'] == 1 ? 'loop' : '';
  22.             $metadata = $attributes['loop'] == 1 ? 'preload="metadata"' : 'preload="auto"';
  23.  
  24.             $uid = 'player_'.get_the_ID().'_'.mt_rand().'_'.mt_rand();
  25.  
  26.             $output .= '<video class="avia_video" '.$image.' '.$autoplay.' '.$loop.' '.$metadata.' controls id="'.$uid.'" >';
  27.  
  28.             foreach ($types as $key => $type)
  29.             {
  30.                 if($path_split[2] == $key || avia_is_200($path_split[1].'.'.$key))
  31.                 {
  32.                     $output .= '    <source src="'.$path_split[1].'.'.$key.'" '.$type.' />';
  33.                 }
  34.             }
  35.  
  36.             $output .= '</video>';
  37.         }
  38.  
  39.         return $output;
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement