Beispiel #1
0
        public static void BrowseHandler(TextBox tbPath, ListView.ListViewItemCollection items)
        {
            var fd = new FolderBrowserDialog();

            fd.RootFolder = Environment.SpecialFolder.MyComputer;

            if (!Directory.Exists(tbPath.Text))
            {
                if (fd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                tbPath.Text = fd.SelectedPath;
            }

            items.Clear();
            var wmp = new WindowsMediaPlayer();

            var exts   = new Regex(@"\.(mp[234a]|m4a|aac|mka|wma|wav|flac)$");
            var audios = Directory.EnumerateFiles(tbPath.Text).Where(x => exts.IsMatch(x));

            foreach (var file in audios)
            {
                TrackMetadata meta = GetMetadata(wmp, file);
                items.Add(new ListViewItem(meta.ListItem)
                {
                    Tag = meta
                });
            }
        }
Beispiel #2
0
        public static TrackMetadata GetMetadata(WindowsMediaPlayer wmp, string file)
        {
            var medium = wmp.newMedia(file);

            long.TryParse(medium.getItemInfo("FileSize"), out long size);
            // getItemInfoByAtom은 구현이 안 된듯 하다.
            var meta = new TrackMetadata()
            {
                Title    = medium.name,
                Artist   = medium.getItemInfo("Artist"),
                Duration = new TimeSpan(Convert.ToInt64(medium.duration * 10000000)),
                FileSize = size,
                Path     = file
            };

            return(meta);
        }