2

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:

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.

rderik
  • 460
  • 5
  • 18
  • It seems that the server would indeed handle the request if we set Rails to send the path to the file. Currently, Rails is sending the file as raw data (see: https://github.com/rails/rails/blob/v5.2.0/activestorage/app/controllers/active_storage/disk_controller.rb For Rails5.2.0). If we wanted Rails to hand the control to the server we should instead of using `send_data` use `send_file` and that has been fixed in the master branch of rails see:(https://github.com/rails/rails/blob/master/activestorage/app/controllers/active_storage/disk_controller.rb) so it is a matter of just waiting. – rderik Jun 19 '18 at 13:53
  • We'll following the discussion on github for ActiveStorage: https://github.com/rails/rails/issues/32193 we can see that the commit doesn't fix the issue. Still working on it. If someone has more thoughts let me know if I find something new I'll post here to help anyone on the same boat. At the moment one proposed solution is to use: `file_status, file_headers, file_body = Rack::File.new(nil).serving(request, path) response.status = file_status response.headers.merge!(file_headers) self.response_body = file_body` – rderik Jun 21 '18 at 08:21

0 Answers0