Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2023-09-15 09:19:05

nikolaos70
New Member
Registered: 2023-06-13
Posts: 3

Link to mp3 file in audio tag

I have <audio /> tags on my page: https://test.axu.ru/testaudio.php

This option doesn’t work (1):

<audio autoplay controls> <source src=“https://test.axu.ru/file_download/45” type=“audio/mpeg”> </audio>

This also doesn’t (2):

<audio autoplay controls> <source src=”<txp:file_download id=“45” />” type=“audio/mpeg”> </audio>

Only works this option (3):

<audio autoplay controls> <source src=“https://test.axu.ru/files/45.mp3” type=“audio/mpeg”> </audio>

Is it possible to use (1) and (2) options? What must i do to correct it?

Thank you!

Offline

#2 2023-09-15 10:26:57

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,436
Website GitHub

Re: Link to mp3 file in audio tag

Hello and welcome to Textpattern.

Option 1 doesn’t work because Txp won’t stream from the file_download route.
Option 2 doesn’t work because, by default, that tag generates a complete file_download name and link. You might have more luck with <txp:file_download_link id="45" /> but even that won’t work for the same reason as above.

What will work is this:

<txp:file_download_list id="45">
<a href="/files/<txp:file_download_name />"><txp:file_download_name /></a>
</txp:file_download_list>

That creates a file download list of 1 item of id="45" and then outputs its name as part of a manually-constructed anchor link tag.

You will need to embed this into your <audio> tag which might prove tricky so I would advise doing what Kjeld did in this post. Create a shortcode Form called media_audio exactly as he did and then simply call:

<txp::media_audio id="45" />

You can alter the media_audio Form to taste (e.g. adding autoplay and classes, changing/removing the wrapper <p> tag if necessary, etc).

Hope that helps.

P.S. if you ever want a more fully-featured audio/video solution, then I think the oui_player plugin still works.

Last edited by Bloke (2023-09-15 11:35:58)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2023-09-15 11:10:47

nikolaos70
New Member
Registered: 2023-06-13
Posts: 3

Re: Link to mp3 file in audio tag

It is interesting when site hosts by MS IIS Server there are no problems with streaming with (1) and (2) options. Why?

Offline

#4 2023-09-15 11:49:08

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,436
Website GitHub

Re: Link to mp3 file in audio tag

Option 1 isn’t a ‘real’ download file; it’s a URL that Textpattern provides as a convenient redirect to avoid having to use the filename. I’m pretty sure there’s a way to configure these to actually serve as real files or streams but the method escapes me at the moment. Perhaps IIS by default is set to serve mp3 files as streams, whereas Apache (or whatever) on your current server isn’t.

Option 2 would work, but by default the <txp:file_download> tag is passed through the files Form to generate its output. That is set to output a full anchor link, with title and surrounding div and other HTML code. So if you try and embed that inside a src attribute then it’ll create invalid markup.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2023-09-16 19:24:54

nikolaos70
New Member
Registered: 2023-06-13
Posts: 3

Re: Link to mp3 file in audio tag

This is the simple solution that works:

src=”/files/<txp:file_download_id />.mp3”

Thanks!

Offline

Board footer

Powered by FluxBB