MyBB Community Forums

Full Version: Super-duper simple, stupid way to display video attachments.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
On my forum I wanted to have video attachments to appear like so:
[attachment=46103]
Fiddled around for a bit and came up with a super simple solution, thought someone else who's in the same situation might find use from it...

First off, do the obligatory adding of WebM and MP4 to the list of allowed formats in AdminCP>Configuration>Attachment Types...

In attachment.php at around line 80 I added to the list of mime types:
case "video/webm":
case "video/mp4":
Without this it would force-download the videos and wouldn't embed them properly.

In the postbit_attachments_attachment template, add the following to the end:
<div class="AttachmentEmbedSpecial" id="attachment.php?aid={$attachment['aid']}">{$attachment['filename']}</div>


Now, in the postbit template, add this to the end:
<script>
	var vid1 = "<video width=\"560\" height=\"320\" controls=\"controls\" preload=\"metadata\"><source src=\""
	var vid2 = "\" ></video>"
	
	var SteeleDawn = document.getElementsByClassName("AttachmentEmbedSpecial");
	for (i=0;i<SteeleDawn.length;i++)
	{
			
			if (SteeleDawn[i].innerHTML.endsWith(".webm") || SteeleDawn[i].innerHTML.endsWith(".mp4") )
			{
				SteeleDawn[i].innerHTML = vid1 + SteeleDawn[i].id + vid2;
			}
			if (!(SteeleDawn[i].innerHTML.endsWith("</video>")))
			{
				SteeleDawn[i].innerHTML = ""
			}
	}
</script>
There's probably a bunch of places this could go, but it works fine there.

This is a really simplistic way to do it but it works.