Audio attachments don't work when "prevent anons from downloading files" is enabled

AI-generated summary

The discussion revolves around an issue with audio attachments not working when the “prevent anons from downloading files” setting is enabled. bts initially reported inconsistent behavior with uploaded audio files, sometimes displaying an in-line player and other times showing a download link. simon pointed out that the “prevent anons from downloading files” setting is the cause of the issue, as it prevents the creation of an audio player.

bts acknowledged having this setting enabled, but argued that it shouldn’t disable the audio player for logged-in users. They suggested a few possible solutions, including adding a tip to the setting to clarify its impact on inline audio players, or implementing a built-in audio player that allows more control over display and download settings. For now, bts plans to disable the “prevent anons from downloading files” setting to ensure audio playback works correctly.

Not sure if this is a bug but I’m seeing some inconsistent behavior with uploaded audio files.

Yesterday I recently enabled mp3 format for attachments in our forum, and tested a drag-and-drop upload in a PM to myself. This worked as expected with a nice in-line player displaying in the post.

However I just tried again and it’s showing the download link instead. I think I’m doing the same thing as yesterday (drag + drop file into the composer) but different results.

From what I see here from @techAPJ it sounds like the “native player” should be the default for uploaded audio files, correct? — https://meta.discourse.org/t/playing-mp3-next-to-the-button-to-download-the-file/26944/29?u=bts

BTW when I edit the post and look at the raw text, this is what creates the expected native audio player, and is what I got from adding a file in the test PM I sent myself yesterday:

https://forum.troygrady.com/uploads/default/original/2X/3/38d861bfed1a26b23255bbd634263ff63fba1371.mp3

Whereas trying this again today, replying to the earlier PM and dragging in an mp3 upload, I see the following has been inserted in the post instead, giving the download link rather than inline player:

<a class="attachment" href="/uploads/default/original/2X/3/38d861bfed1a26b23255bbd634263ff63fba1371.mp3">Centipede - Backing Track.mp3</a> (2.3 MB)

Do you have the ‘prevent anons from downloading files’ Site Setting enabled? That setting will prevent an audio player from being created.

Ah okay interesting! Thanks — yes I have that setting enabled as I do think it makes sense to prevent anons from downloading files.

But doesn’t seem like that setting should require disabling the audio player for logged in users?

Actually it appears that viewing as an anon user, the native audio player (both playback + download) is disabled anyway even using the raw embed URL rather than wrapping in the <a class="attachment"> tag.

E.g. the last post here, when I’m logged in I can play back and download the one-minute audio file, but viewing as anon it just appears as a non-functional player (no playback or download link):

Short term I guess I can turn off prevent anons from downloading files since for now it’s more just a minor preventative measure and I think it’s more important for audio playback to work correctly.

Also might be kinda fine to just have the behavior in the post linked above (showing disabled player) rather than not show player at all, when that prevent anons from downloading files is on. Or long term maybe Discourse could add a built in (but still super simple) audio player overriding the browser default but allowing more control over display / download settings.

(Assuming no other changes, for now perhaps a tip in that setting would help; to me very unintuitive that a setting re: download permissions would affect the inline audio player!)