Use video player for video attachments
authorMatthias Schmidt <gravatronics@live.com>
Fri, 18 Jan 2019 17:15:22 +0000 (18:15 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Fri, 18 Jan 2019 17:15:22 +0000 (18:15 +0100)
Close #2802

com.woltlab.wcf/templates/__videoAttachmentBBCode.tpl [new file with mode: 0644]
wcfsetup/install/files/lib/system/bbcode/AttachmentBBCode.class.php

diff --git a/com.woltlab.wcf/templates/__videoAttachmentBBCode.tpl b/com.woltlab.wcf/templates/__videoAttachmentBBCode.tpl
new file mode 100644 (file)
index 0000000..da69480
--- /dev/null
@@ -0,0 +1,19 @@
+<div id="attachmentVideo_{@$attachmentIdentifier}" class="videoContainer" style="display: none;">
+       <video src="{link controller='Attachment' object=$attachment}{/link}" controls></video>
+</div>
+
+<a id="attachmentVideoLink_{@$attachmentIdentifier}" href="{link controller='Attachment' object=$attachment}{/link}">{$attachment->filename}</a>
+
+<script data-relocate="true">
+       {* try to determine if browser might be able to play video *}
+       var video = elById('attachmentVideo_{@$attachmentIdentifier}');
+       var canPlayType = elCreate('video').canPlayType('{$attachment->fileType}');
+       
+       if (canPlayType === '') {
+               elRemove(video);
+       }
+       else {
+               elShow(video);
+               elRemove(elById('attachmentVideoLink_{@$attachmentIdentifier}'));
+       }
+</script>
index d4a6c6e65d95708cfbf9895757d39423eed6ab14..89713b829e1406954e8518ad6c2d46f0b267d671 100644 (file)
@@ -3,6 +3,7 @@ namespace wcf\system\bbcode;
 use wcf\data\attachment\GroupedAttachmentList;
 use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
 use wcf\system\request\LinkHandler;
+use wcf\system\WCF;
 use wcf\util\StringUtil;
 
 /**
@@ -152,6 +153,12 @@ class AttachmentBBCode extends AbstractBBCode {
                                
                                return $result;
                        }
+                       else if (substr($attachment->fileType, 0, 6) === 'video/') {
+                               return WCF::getTPL()->fetch('__videoAttachmentBBCode', 'wcf', [
+                                       'attachment' => $attachment,
+                                       'attachmentIdentifier' => StringUtil::getRandomID()
+                               ]);
+                       }
                        else {
                                // file
                                return StringUtil::getAnchorTag(LinkHandler::getInstance()->getLink('Attachment', [