Skip to content

Commit

Permalink
Merge pull request #7 from postyou/dev
Browse files Browse the repository at this point in the history
update to current ContentMedia version
  • Loading branch information
MarkejN authored Jan 6, 2021
2 parents d91c2af + 57aa627 commit b57890e
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 100 deletions.
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"name": "postyou/contao-abr-streaming-bundle",
"description": "Adaptive Bitrate Streaming using Mediaelement.js with MPEG-DASH and HLS manifests",
"description": "Adaptive Bitrate Streaming using Mediaelement.js with MPGEG-DASH and HLS manifests",
"keywords": [
"contao",
"streaming",
"dash",
"hls"
],
"version": "v1.1.0",
"type": "contao-bundle",
"license": "Apache-2.0",
"authors": [{
Expand All @@ -23,8 +22,8 @@
"email": "[email protected]"
},
"require": {
"php": "~7.0",
"contao/core-bundle": "~4.3",
"php": ">=7.0",
"contao/core-bundle": "^4.9",
"contao-components/mediaelement": "~4.2.12"
},
"autoload": {
Expand Down
18 changes: 2 additions & 16 deletions src/Resources/contao/dca/tl_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,13 @@
*/

// Add palette to tl_content
$GLOBALS['TL_DCA']['tl_content']['palettes']['abrstreaming'] = '{type_legend},type,headline;{sources},abrs_playerSRC;{poster_legend:hide},posterSRC;{player_legend},abrs_playerSize,abrs_autoplay;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID;{invisible_legend:hide},invisible,start,stop';
$GLOBALS['TL_DCA']['tl_content']['palettes']['abrstreaming'] = '{type_legend},type,headline;{source_legend},abrs_playerSRC;{player_legend},playerSize,playerOptions,playerStart,playerStop,playerCaption;{poster_legend:hide},posterSRC;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID;{invisible_legend:hide},invisible,start,stop';

// Add fields to tl_content
$GLOBALS['TL_DCA']['tl_content']['fields']['abrs_playerSRC'] = array(
'label' => &$GLOBALS['TL_LANG']['tl_content']['abrs_playerSRC'],
'exclude' => true,
'inputType' => 'fileTree',
'eval' => array('filesOnly'=>true, 'multiple'=>true, 'fieldType'=>'checkbox', 'extensions' =>'mpd, m3u8, mp4, m4v, mov, wmv, webm, ogv', 'mandatory'=>true, 'tl_class'=>'clr autoheight'),
'eval' => array('filesOnly'=>true, 'multiple'=>true, 'fieldType'=>'checkbox', 'extensions' =>'mpd, m3u8', 'mandatory'=>true, 'tl_class'=>'clr autoheight'),
'sql' => "blob NULL"
);
$GLOBALS['TL_DCA']['tl_content']['fields']['abrs_playerSize'] = array(
'label' => &$GLOBALS['TL_LANG']['tl_content']['playerSize'],
'exclude' => true,
'inputType' => 'text',
'eval' => array('multiple'=>true, 'size'=>2, 'rgxp'=>'natural', 'nospace'=>true, 'tl_class'=>'w50'),
'sql' => "varchar(64) NOT NULL default ''"
);
$GLOBALS['TL_DCA']['tl_content']['fields']['abrs_autoplay'] = array(
'label' => &$GLOBALS['TL_LANG']['tl_content']['autoplay'],
'exclude' => true,
'inputType' => 'checkbox',
'eval' => array('tl_class'=>'w50 m12'),
'sql' => "char(1) NOT NULL default ''"
);
173 changes: 124 additions & 49 deletions src/Resources/contao/elements/ContentAbrstreaming.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
*
* Extension for Contao Open Source CMS (contao.org)
Expand All @@ -10,9 +11,17 @@
* @link http://www.postyou.de
* @license http://www.apache.org/licenses/LICENSE-2.0
*/

namespace Postyou\ContaoABRStreamingBundle;

class ContentAbrstreaming extends \ContentElement
use Contao\ContentElement;
use Contao\StringUtil;
use Contao\FilesModel;
use Contao\System;
use Contao\Image;
use Contao\File;

class ContentAbrstreaming extends ContentElement
{

/**
Expand All @@ -23,14 +32,9 @@ class ContentAbrstreaming extends \ContentElement

/**
* Files object
* @var Model\Collection|FilesModel
* @var \Contao\Model\Collection|FilesModel
*/
protected $objFiles;

public function __construct($objModule, $strColumn = 'main')
{
parent::__construct($objModule, $strColumn);
}

/**
* Return if there are no files
Expand All @@ -39,32 +43,47 @@ public function __construct($objModule, $strColumn = 'main')
*/
public function generate()
{
if ($this->abrs_playerSRC == '') {
if (!$this->abrs_playerSRC)
{
return '';
}
$source = \StringUtil::deserialize($this->abrs_playerSRC);

if (empty($source) || !\is_array($source)) {
$source = StringUtil::deserialize($this->abrs_playerSRC);

if (empty($source) || !\is_array($source))
{
return '';
}

$objFiles = \FilesModel::findMultipleByUuidsAndExtensions($source, array('mpd', 'm3u8', 'mp4', 'm4v', 'mov', 'wmv', 'webm', 'ogv'));
$objFiles = FilesModel::findMultipleByUuidsAndExtensions($source, array('mpd', 'm3u8'));

if ($objFiles === null) {
if ($objFiles === null)
{
return '';
}

$request = System::getContainer()->get('request_stack')->getCurrentRequest();

// Display a list of files in the back end
if (TL_MODE == 'BE') {
$return = '<ul>';
if ($request && System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest($request))
{
$return = '<ul>';

while ($objFiles->next()) {
$objFile = new \File($objFiles->path);
$return .= '<li>' . \Image::getHtml($objFile->icon, '', 'class="mime_icon"') . ' <span>' . $objFile->name . '</span> <span class="size">(' . $this->getReadableSize($objFile->size) . ')</span></li>';
}
while ($objFiles->next())
{
$objFile = new File($objFiles->path);
$return .= '<li>' . Image::getHtml($objFile->icon, '', 'class="mime_icon"') . ' <span>' . $objFile->name . '</span> <span class="size">(' . $this->getReadableSize($objFile->size) . ')</span></li>';
}

return $return . '</ul>';
}
$return .= '</ul>';

if ($this->headline)
{
$return = '<' . $this->hl . '>' . $this->headline . '</' . $this->hl . '>' . $return;
}

return $return;
}

$this->objFiles = $objFiles;

Expand All @@ -79,46 +98,102 @@ protected function compile()
/** @var PageModel $objPage */
global $objPage;

$this->Template->poster = false;

// Optional poster
if ($this->posterSRC && ($objFile = FilesModel::findByUuid($this->posterSRC)) !== null)
{
$this->Template->poster = $objFile->path;
}

$objFiles = $this->objFiles;

/** @var FilesModel $objFirst */
$objFirst = $objFiles->current();

// Pre-sort the array by preference
if (\in_array($objFirst->extension, array('mpd','m3u8', 'mp4', 'm4v', 'mov', 'wmv', 'webm', 'ogv'))) {
$arrFiles = array('mpd'=>null, 'm3u8'=>null, 'mp4'=>null, 'm4v'=>null, 'mov'=>null, 'wmv'=>null, 'webm'=>null, 'ogv'=>null);
if (\in_array($objFirst->extension, array('mpd','m3u8')))
{
$this->Template->containerClass = 'video_container';

$arrFiles = array('mpd'=>null, 'm3u8'=>null);
}

$objFiles->reset();

// Convert the language to a locale (see #5678)
$strLanguage = str_replace('-', '_', $objPage->language);

// Pass File objects to the template
while ($objFiles->next()) {
$arrMeta = \StringUtil::deserialize($objFiles->meta);

if (\is_array($arrMeta) && isset($arrMeta[$strLanguage])) {
$strTitle = $arrMeta[$strLanguage]['title'];
} else {
$strTitle = $objFiles->name;
}

$objFile = new \File($objFiles->path);
$objFile->title = \StringUtil::specialchars($strTitle);

$arrFiles[$objFile->extension] = $objFile;
}

$size = \StringUtil::deserialize($this->abrs_playerSize);

if (!\is_array($size) || empty($size[0]) || empty($size[1])) {
$this->Template->size = ' width="640" height="360"';
} else {
$this->Template->size = ' width="' . $size[0] . '" height="' . $size[1] . '"';
}
// Convert the language to a locale (see #5678)
$strLanguage = str_replace('-', '_', $objPage->language);

// Pass File objects to the template
while ($objFiles->next())
{
$arrMeta = StringUtil::deserialize($objFiles->meta);

if (\is_array($arrMeta) && isset($arrMeta[$strLanguage]))
{
$strTitle = $arrMeta[$strLanguage]['title'];
}
else
{
$strTitle = $objFiles->name;
}

$objFile = new File($objFiles->path);
$objFile->title = StringUtil::specialchars($strTitle);

$arrFiles[$objFile->extension] = $objFile;
}

$size = StringUtil::deserialize($this->playerSize);

if (\is_array($size) && !empty($size[0]) && !empty($size[1]))
{
$this->Template->size = ' width="' . $size[0] . '" height="' . $size[1] . '"';
}
else
{
// $this->size might contain image size data, therefore unset it (see #2351)
$this->Template->size = '';
}

$this->Template->files = array_values(array_filter($arrFiles));
$this->Template->autoplay = $this->abrs_autoplay;

$attributes = array('controls' => 'controls');
$options = StringUtil::deserialize($this->playerOptions);

if (\is_array($options))
{
foreach ($options as $option)
{
if ($option == 'player_nocontrols')
{
unset($attributes['controls']);
}
else
{
$attributes[substr($option, 7)] = substr($option, 7);
}
}
}

$this->Template->attributes = $attributes;
$this->Template->caption = $this->playerCaption;

if ($this->playerStart || $this->playerStop)
{
$range = '#t=';

if ($this->playerStart)
{
$range .= $this->playerStart;
}

if ($this->playerStop)
{
$range .= ',' . $this->playerStop;
}

$this->Template->range = $range;
}
}
}
5 changes: 0 additions & 5 deletions src/Resources/contao/languages/de/tl_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,3 @@
* Fields
*/
$GLOBALS['TL_LANG']['tl_content']['abrs_playerSRC'] = array('Video-Dateien', 'Hier können Sie die Video-Datei bzw. – wenn Sie verschiedene Codecs verwenden – die Video-Dateien hinzufügen.');
$GLOBALS['TL_LANG']['tl_content']['autoplay'] = array('Autoplay', 'Video wird automatisch beim Aufruf der Seite abgespielt.');
/**
* Legends
*/
$GLOBALS['TL_LANG']['tl_content']['sources'] = 'Dateien';
25 changes: 10 additions & 15 deletions src/Resources/contao/templates/ce_abrstreaming.html5
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
<?php $this->extend('block_unsearchable'); ?>

<?php $this->block('content'); ?>
<!-- Überschrift -->
<?php if ($this->headline): ?>
<<?php echo $this->hl; ?>>
<?php echo $this->headline; ?>
</<?php echo $this->hl; ?>>
<?php endif; ?>

<video class="abr-streaming<?php if ($this->autoplay): ?> autoplay<?php endif; ?>" <?php if ($this->poster): ?>
poster="
<?= $this->poster ?>" preload="none"
<?php endif; ?>
<?= $this->size ?> controls playsinline webkit-playsinline>
<?php foreach ($this->files as $file): ?>
<source type="<?= $file->mime ?>" src="<?= $file->path ?>" title="<?= $file->title ?>">
<?php endforeach; ?>
</video>
<figure class="<?= $this->containerClass ?>">
<video class="abr-streaming<?php if ($this->autoplay): ?> autoplay<?php endif; ?>"<?= $this->size ?><?php if ($this->poster): ?> poster="<?= $this->poster ?>"<?php endif; ?><?php if ($this->preload): ?> preload="<?= $this->preload ?>"<?php endif; ?> <?= implode(' ', $this->attributes) ?>>
<?php foreach ($this->files as $file): ?>
<source type="<?= $file->mime ?>" src="<?= $file->path.$this->range ?>" title="<?= $file->title ?>">
<?php endforeach; ?>
</video>
<?php if ($this->caption): ?>
<figcaption class="caption"><?= $this->caption ?></figcaption>
<?php endif; ?>
</figure>

<?php $this->endblock(); ?>
15 changes: 4 additions & 11 deletions src/Resources/contao/templates/js_mediaelement_dash.html5
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,18 @@
$GLOBALS['TL_CSS'][] = 'assets/mediaelement/css/mediaelementplayer.min.css|static';
$GLOBALS['TL_CSS'][] = 'bundles/postyoucontaoabrstreaming/css/qualityselection.css|static';
?>

<script src="<?= TL_ASSETS_URL ?>assets/mediaelement/js/mediaelement-and-player.min.js"></script>
<script src="<?= $this->asset('js/mediaelement-and-player.min.js', 'contao-components/mediaelement') ?>"></script>
<script src="bundles/postyoucontaoabrstreaming/js/qualityselection.js"></script>
<script>
(function () {
var e = document.querySelectorAll(':not(picture) > video, :not(picture) > audio');
var e = document.querySelectorAll(':not(picture) > video');
for (var i = 0; i < e.length; i++) {
if (e[i].classList.contains('abr-streaming')) {
if (e[i].classList.contains('autoplay')) var autoplay = true;
var player = new MediaElementPlayer(e[i], {
// Put custom options here
features: ['playpause', 'current', 'progress', 'duration', 'volume', 'qualityselection', 'fullscreen'],
features: e[i].controls? ['playpause', 'current', 'progress', 'duration', 'volume', 'qualityselection', 'fullscreen'] : [],
renderers: ['native_dash', 'native_hls'],
pluginPath: "<?= Environment::get('path') ?>/assets/mediaelement/plugins/",
success: function (media, node, instance) {
if (autoplay) {
player.play();
}
}
pluginPath: "<?= Environment::get('path') ?>/assets/mediaelement/plugins/"
});
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/Resources/public/css/qualityselection.css
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,8 @@
.mejs__qualityselection-selector label.current,
.mejs-qualityselection-selector label.current {
color: #21f8f8;
}

.mejs__container .mejs__controls:empty {
visibility: hidden !important;
}

0 comments on commit b57890e

Please sign in to comment.