| | |
Getting Audio File Length in C#
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2006
Posts: 1
Reputation:
Solved Threads: 0
Hi All
I am looking to be able to get the length of any audio file in seconds. Formats are WAV, MP3 and DSS. Is there anything like this...
Any help would be appreciated
Mike
I am looking to be able to get the length of any audio file in seconds. Formats are WAV, MP3 and DSS. Is there anything like this...
C# Syntax (Toggle Plain Text)
int seconds = myFile.AudioLength();
Any help would be appreciated
Mike
•
•
Join Date: Jul 2007
Posts: 1
Reputation:
Solved Threads: 0
Hey hi !
I'm trying to do the same thing to try to see the lenght of an audio file. Did you ever knew how to do it. All I know is how to get the bytes size of the file but don't know how to get the time thanks.
Jose
I'm trying to do the same thing to try to see the lenght of an audio file. Did you ever knew how to do it. All I know is how to get the bytes size of the file but don't know how to get the time thanks.
Jose
•
•
•
•
Hi All
I am looking to be able to get the length of any audio file in seconds. Formats are WAV, MP3 and DSS. Is there anything like this...
C# Syntax (Toggle Plain Text)
int seconds = myFile.AudioLength();
Any help would be appreciated
Mike
•
•
Join Date: Jul 2008
Posts: 47
Reputation:
Solved Threads: 0
0
#4 Oct 7th, 2009
well, I don't remember the exact details, but maybe you can use windows properties for this?
I know there is a way to access the properties of a file under windows. If you were to access the time detail form the soundfile... that might work. Not sure if it would help for .dss files since I'm not sure windows will know what to do with those.
Hope this helps at least a little.
I know there is a way to access the properties of a file under windows. If you were to access the time detail form the soundfile... that might work. Not sure if it would help for .dss files since I'm not sure windows will know what to do with those.
Hope this helps at least a little.
•
•
Join Date: Jul 2009
Posts: 903
Reputation:
Solved Threads: 144
0
#6 Oct 9th, 2009
I saw on this calculation on the web, but I don't have a .dss file to test it with...
C# Syntax (Toggle Plain Text)
public static long GetDSSDuration(string fileName) { FileInfo fi = new FileInfo(fileName); long size = fi.Length; long length = (long)(((size * 1.1869) - ((size / 1054) * 210)) / 1054); if (length > 1000) { length = (long)(length * (0.61 + ((length / 100) * 0.0005))); } else { length = (long)(length * (0.61 + ((length / 100) * 0.0015))); } return length; }
•
•
Join Date: Jul 2008
Posts: 47
Reputation:
Solved Threads: 0
0
#8 Oct 10th, 2009
Assuming that the formula outputs time in seconds, all you would have to do is put "length = length / 60;" just before "return length" and that should work fine. (his/her solution is far better then mine since it actually calculates the value for the audiofile, I don't think windows recognizes .dss files, so it won't have any detailed info on it either)
•
•
Join Date: Jul 2009
Posts: 903
Reputation:
Solved Threads: 144
0
#10 Oct 10th, 2009
How many seconds duration is the dss file(s) that is off by 10 - 30 seconds? Also, do you have many dss files of varying durations? If you do, and the calculation varies proportionately to an increase in duration, you could adjust the calculation to accommodate a better approximation.
EDIT: Also, be sure you are not truncating/rounding the time when calculating minutes in the divide by 60 division...
EDIT: Also, be sure you are not truncating/rounding the time when calculating minutes in the divide by 60 division...
Last edited by DdoubleD; Oct 10th, 2009 at 8:38 am.
![]() |
Similar Threads
- Play a .wav file (Java)
- Using pygame to get MIDI file length (Python)
- Audio Website Testimonial (Promotion and Marketing Plans)
- Recommended Web Hosts (Web Hosting Deals)
- Sending audio data over HTTP problem (Java)
Other Threads in the C# Forum
- Previous Thread: database and setup project
- Next Thread: Naming Convention
| Thread Tools | Search this Thread |
.net access algorithm angle array barchart bitmap box broadcast c# capturing check checkbox client combobox control conversion convert csharp custom database datagrid datagridview dataset datetime dbconnection degrees delegate design development disappear draganddrop drawing encryption enum event excel file firefox form format forms function gdi+ httpwebrequest image index input install java label leak libraries list listbox mandelbrot math monodevelop mouseclick msword mysql operator path pause photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox round server sleep socket sql statistics stream string table tcpclientchannel text textbox thread time timer update usercontrol validation virtualization visualbasic visualstudio webbrowser windows winforms wpf xml





