It started as a simple use for ActiveStorage, just store some audio files in mp3 format (done easily) and display it on the site:
<%= audio_tag url_for(recording.audio_file), controls: true, preload: "none" %>
I tested on Chrome and Firefox and it works, I can play the audio no problem as many times as I want, but when I tested it on Safari I came across the problem that Safari assumes that the server supports Content-Range so Safari thinks it is a Live Stream and the html5 element can only play once.
So I've been searching the Internet for how to fix this and I've seen answers that point to:
- The webserver doesn't support it but I'm using Apache 2.4 and from 2.2 it supports Content-Range by default.
- Safari is rubish which doesn't help me
- You should implement it on Rails well yea that could be a solution, but I checked the code for ActiveStorage (https://github.com/rails/rails/blob/master/activestorage/lib/active_storage/service/disk_service.rb#L41) but I would have to change it (I found this answer rails media file stream accept byte range request through send_data or send_file method) that seems helpful but it would seem as if it should be easier and shouldn't require me to change the implementation of ActiveStorage.
- So the last possibility is that I'm not understanding the concept of how everything is woven together and the answer is probably simple and easy to implement so that is why there is no information on the internet because it's obvious but I can't really figure it out.
Anyone has any pointers on how to use ActiveStorage to store and provide audio that can be presented using the html5 audio tag that works for Chrome, FireFox, and Safari.
Thanks for your help.