[FEATURE] Add autoplay option for filetype audio and video 25/38625/9
authorFrans Saris <franssaris@gmail.com>
Fri, 10 Apr 2015 19:40:06 +0000 (21:40 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Sun, 13 Sep 2015 20:29:45 +0000 (22:29 +0200)
With the RenderingRegistry introduced with #61800 we have the option
to render audio and video tags. #66366 adds a ViewHelper so you
can use the Renderer classes in FE.
What is missing is a convenient way for the editors to enable
autoplay for a audio or video file attached to a Content Element.

This change adds a autoplay checkbox to sys_file_reference and
enhances the AudioTagRenderer and VideoTagRenderer to use this
value when set.

Releases: master
Resolves: #66371
Change-Id: I4c551c0e966af406859641e21833eb12586c55e5
Reviewed-on: http://review.typo3.org/38625
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Michael Oehlhof <typo3@oehlhof.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/core/Classes/Resource/Rendering/AudioTagRenderer.php
typo3/sysext/core/Classes/Resource/Rendering/VideoTagRenderer.php
typo3/sysext/core/Configuration/TCA/sys_file_reference.php
typo3/sysext/core/Documentation/Changelog/master/Feature-66371-IntroduceAutoplayOptionForVideoAndAudioFiles.rst [new file with mode: 0644]
typo3/sysext/core/ext_tables.sql
typo3/sysext/lang/locallang_tca.xlf

index a2ff205..1fb3497 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Core\Resource\Rendering;
  */
 
 use TYPO3\CMS\Core\Resource\FileInterface;
+use TYPO3\CMS\Core\Resource\FileReference;
 
 /**
  * Class AudioTagRenderer
@@ -62,6 +63,15 @@ class AudioTagRenderer implements FileRendererInterface {
         * @return string
         */
        public function render(FileInterface $file, $width, $height, array $options = array(), $usedPathsRelativeToCurrentScript = FALSE) {
+
+               // If autoplay isn't set manually check if $file is a FileReference take autoplay from there
+               if (!isset($options['autoplay']) && $file instanceof FileReference) {
+                       $autoplay = $file->getProperty('autoplay');
+                       if ($autoplay !== NULL) {
+                               $options['autoplay'] = $autoplay;
+                       }
+               }
+
                $additionalAttributes = array();
                if (!isset($options['controls']) || !empty($options['controls'])) {
                        $additionalAttributes[] = 'controls';
index fd1daae..4cc281b 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Core\Resource\Rendering;
  */
 
 use TYPO3\CMS\Core\Resource\FileInterface;
+use TYPO3\CMS\Core\Resource\FileReference;
 
 /**
  * Class VideoTagRenderer
@@ -62,6 +63,15 @@ class VideoTagRenderer implements FileRendererInterface {
         * @return string
         */
        public function render(FileInterface $file, $width, $height, array $options = array(), $usedPathsRelativeToCurrentScript = FALSE) {
+
+               // If autoplay isn't set manually check if $file is a FileReference take autoplay from there
+               if (!isset($options['autoplay']) && $file instanceof FileReference) {
+                       $autoplay = $file->getProperty('autoplay');
+                       if ($autoplay !== NULL) {
+                               $options['autoplay'] = $autoplay;
+                       }
+               }
+
                $additionalAttributes = array();
                if (!isset($options['controls']) || !empty($options['controls'])) {
                        $additionalAttributes[] = 'controls';
index 8ea5d65..2481c77 100644 (file)
@@ -226,7 +226,15 @@ return array(
                        'config' => array(
                                'type' => 'imageManipulation'
                        )
-               )
+               ),
+               'autoplay' => array(
+                       'exclude' => 1,
+                       'label' => 'LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.autoplay',
+                       'config' => array(
+                               'type' => 'check',
+                               'default' => 0
+                       )
+               ),
        ),
        'types' => array(
                // Note that at the moment we define the same fields for every media type.
@@ -274,6 +282,20 @@ return array(
                                link,description,--linebreak--,crop
                                ',
                ),
+               // Used for everything that is a video
+               'videoOverlayPalette' => array(
+                       'showitem' => '
+                               title,description,--linebreak--,autoplay
+                               ',
+                       'canNotCollapse' => TRUE
+               ),
+               // Used for everything that is a audio file
+               'audioOverlayPalette' => array(
+                       'showitem' => '
+                               title,description,--linebreak--,autoplay
+                               ',
+                       'canNotCollapse' => TRUE
+               ),
                // File palette, hidden but needs to be included all the time
                'filePalette' => array(
                        'showitem' => 'uid_local, hidden, sys_language_uid, l10n_parent',
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-66371-IntroduceAutoplayOptionForVideoAndAudioFiles.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-66371-IntroduceAutoplayOptionForVideoAndAudioFiles.rst
new file mode 100644 (file)
index 0000000..e68cbae
--- /dev/null
@@ -0,0 +1,63 @@
+=====================================================================
+Feature: #66371 - Introduce autoplay option for video and audio files
+=====================================================================
+
+Description
+===========
+
+The RenderingRegistry added with #61800 introduced the option to render video and audio tags with the new ``MediaViewHelper`` added with #66366.
+To improve the usability of this feature an autoplay checkbox has been added to the ``sys_file_reference`` records to enable the editor to configure
+this option on a per file basis.
+
+To make the autoplay option available in sys_file_reference records, make use of the new palettes ``videoOverlayPalette`` and ``audioOverlayPalette``
+in your TCA.
+
+However, the autoplay property of the ``sys_file_reference`` is only taken into account if the view helper does not explicitly specify an autoplay
+option.
+
+Examples:
+---------
+
+Example config of an sys_file_reference field in TCA:
+
+.. code-block:: php
+
+       'media' => array(
+               'exclude' => 1,
+               'label' => 'Media',
+               'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
+                       'media',
+                       array(
+                               'foreign_types' => array(
+                                       \TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => array(
+                                               'showitem' => '
+                                                       --palette--;;audioOverlayPalette,
+                                                       --palette--;;filePalette',
+                                       ),
+                                       \TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => array(
+                                               'showitem' => '
+                                                       --palette--;;videoOverlayPalette,
+                                                       --palette--;;filePalette',
+                                       )
+                               )
+                       ),
+                       'wav,mpeg,mp4,ogg'
+               )
+       )
+
+
+.. code-block:: html
+
+       <code title="MP4 Video Object with autoplay option set regardless of sys_file_reference checkbox">
+               <f:media file="{file}" width="400" height="375" additionalConfig="{autoplay: '1'}" />
+       </code>
+       <output>
+               <video width="400" height="375" controls autoplay><source src="fileadmin/user_upload/my-video.mp4" type="video/mp4"></video>
+       </output>
+
+        <code title="MP4 Video Object without autoplay option set will respect the configuration of the sys_file_reference record">
+               <f:media file="{file}" width="400" height="375" />
+       </code>
+       <output>
+               <video width="400" height="375" controls><source src="fileadmin/user_upload/my-video.mp4" type="video/mp4"></video>
+       </output>
index 7053a53..2e7f764 100644 (file)
@@ -417,6 +417,7 @@ CREATE TABLE sys_file_reference (
        link varchar(1024) DEFAULT '' NOT NULL,
        downloadname tinytext,
        crop varchar(4000) DEFAULT '' NOT NULL,
+       autoplay tinyint(4) DEFAULT '0' NOT NULL,
 
        PRIMARY KEY (uid),
        KEY parent (pid,deleted),
index c8a7dd2..0b98fd9 100644 (file)
                        <trans-unit id="sys_file_reference.crop">
                                <source>Image manipulation</source>
                        </trans-unit>
+                       <trans-unit id="sys_file_reference.autoplay">
+                               <source>Autoplay</source>
+                       </trans-unit>
                        <trans-unit id="sys_file_collection">
                                <source>File collection</source>
                        </trans-unit>