JeevanJames / Id3

Library to read, modify and write ID3 & Lyrics3 tags in MP3 files. Provides an extensible framework for retrieving ID3 information from online services.
Apache License 2.0
41 stars 17 forks source link

Audio File Length 00:00:00 #56

Open XxDaShTixX opened 3 years ago

XxDaShTixX commented 3 years ago

Hello, I have 2 questions/issues that I hope you can help me with:

1) When I try to retrieve the audio file's length (which is clearly set under the Details tab of the file -> Length), it always shows as "00:00:00". Am I doing something wrong or is this not supported?

image image

2) Some MP3 files work just fine, and some I get the Id3Tag as null for some reason. Any particular reason why this might be happening?

This is the basic code I am using to extract the file properties:

string[] filePaths = Directory.GetFiles(Path.Combine(_environment.WebRootPath, "audio/songs")); List<SongModel> files = new List<SongModel>(); foreach (string filePath in filePaths){ using(var mp3 = new Mp3(filePath)){ Id3Tag tag = mp3.GetTag(Id3TagFamily.Version2X); if (tag != null) { files.Add(new SongModel{ Album = tag.Album ?? "", Title = tag.Title ?? "", Artist = tag.Band ?? "", Year = tag.Year ?? "", Length = (tag.Length.Value.Minutes.ToString() + ":" + tag.Length.Value.Seconds.ToString()) ?? "00:00", FileName = Path.GetFileName(filePath) }); } } }