Topic: gem id3lib - how to get track length?


according to the documentation:

the following Code should work:

  require 'rubygems'
  require 'id3lib'

  tag ="/tmp/my.mp3")
  tag.each do |frame|
    p frame

The output is:

{:text=>"DIG", :textenc=>0, :id=>:TMED}
{:text=>"304587", :textenc=>0, :id=>:TLEN}
{:text=>"genre", :textenc=>0, :id=>:TCON}
{:text=>"1", :textenc=>0, :id=>:TRCK}
{:text=>"My Album", :textenc=>0, :id=>:TALB}
{:text=>"My Artist", :textenc=>0, :id=>:TPE1}
{:text=>"My Track", :textenc=>0, :id=>:TIT2}

So far, so good, but how do i get the track length?

I thought

{:text=>"304587", :textenc=>0, :id=>:TLEN}

would be the track length, but then i don't know what "304587" means, but certainly it doesn't mean seconds or milliseconds or whatever.

The track-length itself is displayed correctly in my mp3-players, it's 5:05, so i guess the id3-tags are fine.

So, in a nutshell: How can i read the actual track-length?

I poked around in the documentation, but couldn't find anything referring to this question....

Last edited by j0llyr0g3r (2008-11-10 19:21:07)

Re: gem id3lib - how to get track length?


{:text=>"304587", :textenc=>0, :id=>:TLEN}

obviously this is in milliseconds == 5:05.

I wonder how i could NOT see this.......

Anyways, solved.