After getting the path of an mp3 file in the database, I used that path to create a TagLib.File but couldn't read the string. My database I used is Microsoft SQL Server 2019.
using(var db= new KhangDuong())
{
var listTrack = db.Tracks.Where(x=>x.TrackID>1).ToList();
List<Track> track = new List<Track>();
track=listTrack;
foreach (var item in track)
{
TagLib.File tagFile = TagLib.File.Create(@item.Track_path);
AudioFileReader reader = new AudioFileReader(@item.Track_path);
TimeSpan duration = reader.TotalTime;
string artist = tagFile.Tag.Artists[0];
string album = tagFile.Tag.Album;
DAL_ListQueue create = new DAL_ListQueue();
create.createItem(floatLayout, item.TrackName, artist,album,duration.Minutes+":"+duration.Seconds);
}
}
I have copy a path for example:
C:\Users\ACER\Music\Ahxello - Frisbee.mp3
I have tried many ways but it still doesn't work with the item.Track_path string, but a fixed string then it works:
using(var db= new KhangDuong())
{
var listTrack = db.Tracks.Where(x=>x.TrackID>1).ToList();
List<Track> track = new List<Track>();
track=listTrack;
foreach (var item in track)
{
string path = @"C:\Users\ACER\Music\Ahxello - Frisbee.mp3";
TagLib.File tagFile = TagLib.File.Create(path);
AudioFileReader reader = new AudioFileReader(path);
TimeSpan duration = reader.TotalTime;
string artist = tagFile.Tag.Artists[0];
string album = tagFile.Tag.Album;
DAL_ListQueue create = new DAL_ListQueue();
create.createItem(floatLayout, item.TrackName, artist,album,duration.Minutes+":"+duration.Seconds);
}
}
I also tried replacing the above fixed string with item.Track_path but it didn't work.
Here's how I enter the path into the database:
OpenFileDialog file = new OpenFileDialog();
file.Filter = "All Media Files|*.mp3;*.flac;*.m4a;";
file.Multiselect = true;
if (file.ShowDialog() == DialogResult.OK)
{
List<string> files = new List<string>();
files = file.FileNames.ToList();
BUS_Track.addTrack(files, KhangDataView);
}