Automatically playing mp4 uploaded file

AI-generated summary

In a support discussion titled “Automatically playing mp4 uploaded file,” Vinicius_Goncalves asks if it’s possible to autoplay a video on a forum page. Canapin responds by providing HTML code to embed the video with the autoplay attribute, noting that autoplay works without sound, and if sound were present, the muted attribute would also be required. Vinicius_Goncalves follows up asking if the video can loop, to which Canapin confirms adding the loop attribute will enable looping. Don suggests this feature could be integrated into the “Insert Video” theme component, possibly with additional options like nodownload, and could appear in a modal during video uploads. The discussion highlights how to manually enable autoplay and looping for MP4 videos in Discourse using HTML, while also considering future UX improvements via theme components.

Hi team,

Is it possible to put this forum page automatically playing that video whenever anyone just open the page?

Thanks in advance.

Instead of just having the video link handled by Discourse when it bakes the post, you can insert the video HTML element and add the autoplay attribute:

<video width="100%" height="100%" preload="metadata" controls="" autoplay>
      <source src="https://www.simscale.com/forum/uploads/default/original/3X/d/6/d6fab77fb56eeb98ef660d682f344dba4bbb66ce.mp4">
      <a href="https://www.simscale.com/forum/uploads/default/original/3X/d/6/d6fab77fb56eeb98ef660d682f344dba4bbb66ce.mp4">/forum/uploads/default/original/3X/d/6/d6fab77fb56eeb98ef660d682f344dba4bbb66ce.mp4</a>
</video>

Since the video has no sound, it will autoplay. If it had sound, you would have to add the muted attribute as well.

More info:

You can see what HTML tags are allowed in posts here: https://github.com/discourse/discourse/blob/main/app/assets/javascripts/pretty-text/addon/allow-lister.js#L115

Hi @Canapin,

That’s really helpful, and I feel really appreciated for your answer.
BTW, is there any HTML attribute to insert loop for such video? Or you think by inserting this autoplay HTML string it will be automatically in loop?

Thanks once again,

You can add the loop attribute :slight_smile:

Nice @Canapin :slightly_smiling_face: I think it would be a great addition to Insert Video theme component as it has other option like nodownload too. It can probably appear on modal to each video upload. :thinking: