public function getHtml5Code($urls = [], $thumbnail = null)
{
$code = "";
$video = $this->getVideoAsset();
if ($video) {
$duration = ceil($video->getDuration());
$durationParts = ["PT"];
// hours
if ($duration / 3600 >= 1) {
$hours = floor($duration / 3600);
$durationParts[] = $hours . "H";
$duration = $duration - $hours * 3600;
}
// minutes
if ($duration / 60 >= 1) {
$minutes = floor($duration / 60);
$durationParts[] = $minutes . "M";
$duration = $duration - $minutes * 60;
}
$durationParts[] = $duration . "S";
$durationString = implode("", $durationParts);
$code .= '<div id="pimcore_video_' . $this->getName() . '" class="pimcore_tag_video">' . "\n";
$uploadDate = new \DateTime();
$uploadDate->setTimestamp($video->getCreationDate());
$jsonLd = ["@context" => "http://schema.org", "@type" => "VideoObject", "name" => $this->getTitle(), "description" => $this->getDescription(), "uploadDate" => $uploadDate->format(\DateTime::ISO8601), "duration" => $durationString, "contentUrl" => Tool::getHostUrl() . $urls["mp4"]];
if ($thumbnail && !preg_match("@https?://@", $thumbnail)) {
$jsonLd["thumbnailUrl"] = Tool::getHostUrl() . $thumbnail;
}
$code .= "\n\n<script type=\"application/ld+json\">\n" . json_encode($jsonLd) . "\n</script>\n\n";
// default attributes
$attributesString = "";
$attributes = ["width" => $this->getWidth(), "height" => $this->getHeight(), "poster" => $thumbnail, "controls" => "controls", "class" => "pimcore_video"];
if (array_key_exists("attributes", $this->getOptions())) {
$attributes = array_merge($attributes, $this->getOptions()["attributes"]);
}
if (isset($this->getOptions()["removeAttributes"]) && is_array($this->getOptions()["removeAttributes"])) {
foreach ($this->getOptions()["removeAttributes"] as $attribute) {
unset($attributes[$attribute]);
}
}
foreach ($attributes as $key => $value) {
$attributesString .= " " . $key;
if (!empty($value)) {
$quoteChar = '"';
if (strpos($value, '"')) {
$quoteChar = "'";
}
$attributesString .= '=' . $quoteChar . $value . $quoteChar;
}
}
$code .= '<video' . $attributesString . '>' . "\n";
foreach ($urls as $type => $url) {
$code .= '<source type="video/' . $type . '" src="' . $url . '" />' . "\n";
}
$code .= '</video>' . "\n";
$code .= '</div>' . "\n";
}
return $code;
}