RV.
RV.

Reputation: 2842

calculating time duration of a file

Dupe of calculate playing time of a .mp3 file

im reading a audio file(for ex:wav,mp3 etc) and get a long value as duration.now i want to convert that long value into correct time duration(like,00:05:32)

Upvotes: 0

Views: 1625

Answers (3)

aslı
aslı

Reputation: 8914

taglib-sharp gives you the mp3 duration exactly as you like.

and it's this easy to call

TagLib.File mp3file = TagLib.File.Create("exactFilePath");
Console.WriteLine(mp3file.Properties.Duration);

Upvotes: 0

Fredrik Mörk
Fredrik Mörk

Reputation: 158289

Depending on exactly what the long represents, you could probably use one of the TimeSpan constructor overloads to get a TimeSpan object representing the duration of the sound file.

Assuming the long represents milliseconds:

long soundLength = GetSoundLength();
TimeSpan duration = new TimeSpan(0, 0, 0, 0, soundLength);
Console.WriteLine("{0} minutes and {1} seconds", duration.Minutes, duration.Seconds);

Edit: fixed the contstructor call; it was one parameter short.

Upvotes: 4

Peter
Peter

Reputation: 14508

First you should determine what it is that you are receiving as input. Then you can convert this into a TimeSpan object which is easy to work with and display onscreen. See http://msdn.microsoft.com/en-us/library/system.timespan.aspx for more information.

Upvotes: 1

Related Questions