0

As you can see in the Timeline.rb model is that I define Size by the source size, but I want to change that to the source duration of the audiofile.

Current setup

  def size
    (source.size.to_f/10000000).round(1)
  end

I tryed a lot gems and stuff but I doesn't seems to get it working? P.S. files are stored on S3 Amazon.

Any thoughts? Greetings, Chris

Chris Kroon
  • 109
  • 1
  • 5

1 Answers1

0

You're going to have to use a library like taglib because neither Ruby nor Rails have any inbuilt support for audio.

In taglib, you'd do something like this:

require 'taglib'

  def size(file_reference)
    properties = file_reference.audio_properties
    return properties.length
  end

You'd also need to set up a method in your model to set file references (by opening audio files, but you can look that up yourself).

MarsAtomic
  • 10,436
  • 5
  • 35
  • 56
  • That works great thanks! Only taglib isn't working on Heroku... I tryed many buildpacks but most of them are old and does not support ruby 2.3 any thoughts? – Chris Kroon Aug 06 '16 at 13:31
  • There's a taglib buildpack specificallly for [Heroku](https://github.com/mrrad/heroku-buildpack-taglib). Did you try it? This [SO question](http://stackoverflow.com/questions/16106552/constructing-custom-heroku-ruby-rails-buildpack-for-web-app-using-taglib-ruby) may also help. – MarsAtomic Aug 06 '16 at 14:58
  • Yeah I tryed all buildpacks I could find, I end up giving this up.. :) – Chris Kroon Aug 10 '16 at 21:58