Html5 video and audio attachment Player (mp3, mp4, ogg,webm,wav)

Html5 video and audio attachment Player (mp3, mp4, ogg,webm,wav)

Epi

Active member
Epi submitted a new resource:

Simple html5 video and audio attachment Player (mp3, mp4, ogg,webm) - Embed attachment uploads in your thread.

First of a big thank you @jacko who did the hard part here:
https://xenforo.com/community/threads/mp3-attachment-player.7903/

This is a quick and easy way to play audio and video file attachments in your forum instead of downloading it. Jacko did a great job but for someone who has trouble with coding like myself it was hard to figure out how to enable it for other extensions.

I removed players and it works entirely on html5 i assume and might not work on some browsers for some...

Read more about this resource...
 
It seems to me that this approach could be used to add a XFMG audio player for mp3, ogg, mpg, wav.
 
Not able to get .mp4 or any other video files to be shown. The player is displayed but the video is not shown. Clicking on the video link in the browser inspector brings up a 404 error. With MP3 sound files it works perfectly. Is it a problem with XF link system for attachments?
 
Does anyone have/know the equivalent version of this for XF2?

same question from me

I can't find attached_files on v2.2.7.

I've managed to hack this through and I was surprised the fix was soo easy but there's no documentation available here (at least I couldn't find one)

In template attachment_macros find this

Code:
        <xf:elseif is="$attachment.is_video AND $canView" />
            <a class="file-preview" href="{$attachment.direct_url}" target="_blank">
                <video data-xf-init="video-init">
                    <source src="{$attachment.direct_url}" />
                </video>
            </a>

Add the appropriate audio object tags below it
Code:
        <xf:elseif is="$attachment.is_audio AND $canView" />
                <audio controls data-xf-init="audio-init">
                    <source src="{$attachment.direct_url}" type="audio/mpeg" />
                </audio>
            <xf:else />

Result:
1650965998033.webp

One downside is that when the audio is played on the player it is not counted as a view, therefore the Views counter of attachment does not increase.
 
Last edited:
Top Bottom