Re-add checking whether the video can be played by the browser
authorjoshuaruesweg <ruesweg@woltlab.com>
Mon, 22 Jun 2020 16:04:52 +0000 (18:04 +0200)
committerjoshuaruesweg <ruesweg@woltlab.com>
Mon, 22 Jun 2020 16:07:11 +0000 (18:07 +0200)
com.woltlab.wcf/templates/__videoAttachmentBBCode.tpl
wcfsetup/install/files/lib/system/bbcode/AttachmentBBCode.class.php

index 95930a7a5b7fbbfdfd691b0f8dec672bdb6f7d26..10b5fbbd37becec964a59d870d3663cddc47b3e2 100644 (file)
@@ -1,7 +1,20 @@
 <span class="mediaBBCode">
-       <video src="{$attachment->getLink()}" controls></video>
+       <video src="{$attachment->getLink()}" style="display: none;" id="attachmentVideo_{$attachmentIdentifier}" controls></video>
        
        <span class="mediaBBCodeCaption">
                <a href="{$attachment->getLink()}">{$attachment->filename}</a>
        </span>
 </span>
+
+<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);
+       }
+</script>
index 2b8e4cc73267098fde637e19b9fecddeaa66a5d3..c2a28abf6a260b9f40487bdad144dd9be1b51007 100644 (file)
@@ -160,6 +160,7 @@ class AttachmentBBCode extends AbstractBBCode {
                        else if (substr($attachment->fileType, 0, 6) === 'video/' && $parser->getOutputType() == 'text/html') {
                                return WCF::getTPL()->fetch('__videoAttachmentBBCode', 'wcf', [
                                        'attachment' => $attachment,
+                                       'attachmentIdentifier' => StringUtil::getRandomID(),
                                ]);
                        }
                        else {