Add audio player for embedded audio attachments
authorjoshuaruesweg <ruesweg@woltlab.com>
Wed, 24 Jun 2020 18:11:37 +0000 (20:11 +0200)
committerjoshuaruesweg <ruesweg@woltlab.com>
Wed, 24 Jun 2020 18:28:59 +0000 (20:28 +0200)
Closes #3231

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

diff --git a/com.woltlab.wcf/templates/__audioAttachmentBBCode.tpl b/com.woltlab.wcf/templates/__audioAttachmentBBCode.tpl
new file mode 100644 (file)
index 0000000..1adb76e
--- /dev/null
@@ -0,0 +1,22 @@
+<span class="mediaBBCode">
+       <audio src="{$attachment->getLink()}" style="display: none;" id="attachmentAudio_{$attachmentIdentifier}" controls></audio>
+       
+       <span class="mediaBBCodeCaption">
+               <a href="{$attachment->getLink()}">{$attachment->filename}</a>
+       </span>
+</span>
+
+<script data-relocate="true">
+       (function () {
+               {* try to determine if browser might be able to play audio *}
+               var audio = elById('attachmentAudio_{@$attachmentIdentifier}');
+               var canPlayType = audio.canPlayType('{$attachment->fileType}');
+               
+               if (canPlayType === '') {
+                       elRemove(audio);
+               }
+               else {
+                       elShow(audio);
+               }
+       })();
+</script>
index c2a28abf6a260b9f40487bdad144dd9be1b51007..8f0503c394816ea9738ae0dddc9d21b9dc46fb89 100644 (file)
@@ -163,6 +163,12 @@ class AttachmentBBCode extends AbstractBBCode {
                                        'attachmentIdentifier' => StringUtil::getRandomID(),
                                ]);
                        }
+                       else if (substr($attachment->fileType, 0, 6) === 'audio/' && $parser->getOutputType() == 'text/html') {
+                               return WCF::getTPL()->fetch('__audioAttachmentBBCode', 'wcf', [
+                                       'attachment' => $attachment,
+                                       'attachmentIdentifier' => StringUtil::getRandomID(),
+                               ]);
+                       }
                        else {
                                // file
                                return StringUtil::getAnchorTag($attachment->getLink(), $attachment->filename);