Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2024-06-20 20:03:50
- imazer
- New Member
- Registered: 2024-06-19
- Posts: 3
Audio File Failure
I have a mystery that someone here may have a clue about.
For several years, I’ve had a small, personal, Textpattern-based website. It is largely for fun and I like learning what goes on behind the scenes with the code. There have been no crippling problems, just an interesting learning curve.
But recently I decided to add a couple of audio files to one of my articles. I found instructions at Texpattern Tips. <https://textpattern.tips/embed-audio-files-using-native-tags> and followed the recommendations. Unfortunately, after going through the supposedly correct steps, the code in my article fails to call the files. You can see the audio controls in the article, but they do not function.
Here is the relevant article page: <https://imazerweb.com/middle/21/some-older-trance-music>
The site is HTML5 and I am running Textpattern version: 4.8.8, with only one diagnostic oddity:
“The following PHP functions (which may be necessary to run Textpattern) are disabled on your server: opcache_get_status”. I doubt this is creating the problem, but if so I think this is a server/apache choice and not something I can change.
The m4a music files are sitting in my “files” folder, which is under “httpsdocs” in my site file structure. And here is the content of the form (named “Audio” under form type ”miscellaneous”) that I use for audio tracks:
<audio controls>
<txp:variable name="audio_file" value='<txp:yield name="title" />' />
<txp:if_variable name="audio_file">
<txp:if_yield name="m4a">
<source src="/files/<txp:variable name="audio_file" />.m4a" type="audio/m4a">
</txp:if_yield>
<txp:if_yield name="mp3">
<source src="/files/<txp:variable name="audio_file" />.mp3" type="audio/mpeg">
</txp:if_yield>
<txp:if_yield name="ogg">
<source src="/files/<txp:variable name="audio_file" />.ogg" type="audio/ogg">
</txp:if_yield>
</txp:if_variable>
Your browser does not support the audio element.
</audio>
And this is the code on the article page used to call the files:
<audio controls>
<source src="/files/Trance1a.m4a" type="audio/m4a">
</audio>
and,
<audio controls>
<source src="/files/Trance 2.m4a" type="audio/m4a">
</audio>
I would greatly appreciate any help!
Offline
Re: Audio File Failure
/files/Trance1a.m4a
gives 403 forbidden. The other file the same, but may not work anyway, since the space in the filename is not escaped (what, %20?).
The page also has about six html typos that are unrelated. Might want to run it through an html validator.
Offline
Offline
Re: Audio File Failure
Maybe the files folder has a .htaccess file that prevents direct access?
Offline
Re: Audio File Failure
I tried it out with some test files on v4.8.8 and the following works on a test server:
<txp:if_yield name="title">
<audio controls>
<txp:if_yield name="m4a">
<source src="/files/<txp:yield name="title" />.m4a" type="audio/mp4">
</txp:if_yield>
<txp:if_yield name="mp3">
<source src="/files/<txp:yield name="title" />.mp3" type="audio/mpeg">
</txp:if_yield>
<txp:if_yield name="ogg">
<source src="/files/<txp:yield name="title" />.ogg" type="audio/ogg">
</txp:if_yield>
<txp:if_yield name="wav">
<source src="/files/<txp:yield name="title" />.wav" type="audio/wav">
</txp:if_yield>
Your browser does not support the audio element.
</audio>
</txp:if_yield>
I used the shortcode to output the code as follows (and uploaded the file in m4a, mp3, ogg and wav formats) …
<txp::audio title="test_filename" m4a mp3 ogg wav />
… but your version with the pure HTML should also work (if you wrote it as pure HTML in your article, i.e. not using the txp::audio tag, your audio form was never referenced).
Takeaways:
- The code from the tutorial appears to work, but can be simplified: you don’t need the variable, you can test straight for
if_yield name="title"
. I’d also wrap that around the entireaudio
tag to avoid outputting an empty element if you forget to specify a title. No title, no output. - It needs the mime type
audio/mp4
to be recognised (in Safari at least). I’ll update Yiannis’ tutorial on textpattern.tips. - On my local file system, it is tolerant of a space in the filename, but other servers may be stricter = it would be safer to use underscores or hyphens in place of spaces in the filenames.
- As Pete/kuopassa says, check you don’t have something blocking reading the files.
TXP Builders – finely-crafted code, design and txp
Offline
Re: Audio File Failure
AddType audio/mp4 m4a
in .htaccess
might fix a file-type mismatch with the extension. I assume that this and the explicit type="audio/mp4"
in the html are two ways of achieving the same thing.
Offline
#7 2024-06-22 21:40:27
- imazer
- New Member
- Registered: 2024-06-19
- Posts: 3
Re: Audio File Failure
First, I wish to thank those of you who responded. Thank you for your time and advice!
Alas, after much staring and tinkering, I’ve failed to solve this.
AFAICT, nothing in the .htaccess will stop the function of the article’s code calling the audio files. I played around with that code a bit, including adding text to allow for specific codexes. It changed nothing. I also uploaded several different audio files with differing codexes to my server. And I shifted around the precise way the files’ codex types were represented in the atticle’s call-out code. No joy.
I find it strange that — despite parking my audio files in the server file-structure under “files” and the fact that the developer tools from the four browsers I used all actually show that specific url location — I still get some version of:
“Failed to load resource: the server responded with a status of 404”
(If I click the link in Vivaldi’s developer tools, I get the formal Textpattern page for 404.)
So here I am, looking at those files, sitting as they are at the very spot they are supposed to be, while all my browsers say they can’t be found. I still suspect the mistake is still between my ears, but…
———
Even with that, I have been otherwise quite happy with Textpatten for years!
—John
Offline
Re: Audio File Failure
Check your files urls: https://imazerweb.com/httpsdocs/files/Trance_1.mp3
. I guess it should be imazerweb.com/files/Trance_1.mp3, which plays quite well.
Offline
Re: Audio File Failure
etc wrote #337339:
Check your files urls:
https://imazerweb.com/httpsdocs/files/Trance_1.mp3
. I guess it should be imazerweb.com/files/Trance_1.mp3, which plays quite well.
what day is it?
…. texted postive
Offline
#10 2024-06-23 20:41:16
- imazer
- New Member
- Registered: 2024-06-19
- Posts: 3
Re: Audio File Failure
Great Googly-Moogly yes! Thanks bloatware, et. al.
Both files finally work just fine now. Odd that I had tried this configuration earlier and it failed. In fact, after I changed the address of the second file, it still took a while to kick in. And I am still puzzled as to why dropping the httpsdocs text did the trick. I’m obviously missing something about server file structures.
Anyway, thanks to all who lend their brains to this!
—John
Offline
Pages: 1