Guest User

avia_html5_video_embed

a guest
May 3rd, 2018
929
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 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"'), $autoplay = false)
  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 = $autoplay == true ? 'autoplay' : '';
  21.  
  22.             $uid = 'player_'.get_the_ID().'_'.mt_rand().'_'.mt_rand();
  23.  
  24.             $output .= '<video class="avia_video" '.$image.' '.$autoplay.' preload="metadata" controls id="'.$uid.'" >';
  25.  
  26.             foreach ($types as $key => $type)
  27.             {
  28.                 if($path_split[2] == $key || avia_is_200($path_split[1].'.'.$key))
  29.                 {
  30.                     $output .= '    <source src="'.$path_split[1].'.'.$key.'" '.$type.' />';
  31.                 }
  32.             }
  33.  
  34.             $output .= '</video>';
  35.         }
  36.  
  37.         return $output;
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment